Add Default Value in DropDownList Control

Posted: April 14, 2011 in ASP.Net

Sometimes you may want to add a default item into a DropDownList control after it has been data bound. For my examply I am going to show ALL as the first option to select. You can do this in two ways :
First Method
You can set the AppendDataBoundItems to True as follows and add a default list item:

<asp:DropDownList ID="DropDownList1" AppendDataBoundItems="true" runat="server" DataTextField="<text_field>" DataValueField="<value_field>">
  <asp:ListItem Text="ALL" Value="" />

Second Method
A default ListItem can be added to a DropDownList control programmatically with the following syntax after binding data to the DropDownList:

DropDownList1.Items.Insert(0, new ListItem("ALL", "");

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s