Jan 22 2006

ListControl property : AppendDataBoundItems

Category: ASP.NET 2.0 - GeneralBil@l @ 12:30

In ASP.NET 1.1, we used to bind a ListControl or any other control inheriting from it to some source of data, after that we used to add a new item at location 0 to tell the user to choose a value, like :  -- Choose a Value --

We always had to do so AFTER binding the ListControl to its data source, else the binding will remove all previous items in the ListControl.

Today, in ASP.NET 2.0, we have the ListControl's property, called AppendDataBoundItems, once this property is set to true, this tells the ListControl NOT to clear the ListControl items before binding to data, so now we can add an item on the top of the ListControl, then simply bind the ListControl to the data source we have. an example is given beloe:

this.ddlItems.Items.Add("- Choose an Item -");
this.ddlItems.AppendDataBoundItems = true;
this.ddlItems.DataSource = CreateDataSource();
this.ddlItems.DataBind();
this.ddlItems.DataTextField = "Name";
this.ddlItems.DataValueField = "ID";

Hope that helps you

Regards

Tags:

Comments are closed