HOW TO: Add a default ListItem to a DropDownList

This can be done one of 2 ways. A default ListItem can be added to a DropDownList programmatically with the following syntax after binding data to the DropDownList:

//Code here to populate DropDownList

DropDownListID.Items.Insert(0, new ListItem("Please Select One", "Default value")

 

This will add a ListItem to index 0, which will be the first ListItem.

In .NET 2.0, this can be done declaratively using the AppendDataBoundItems property. This will append all data-bound ListItems to the DropDownList, leaving those you add manually as the first selections.

<asp:DropDownList ID=DropDownListID AppendDataBoundItems=true runat=server>

<asp:ListItem Text=Please Select One Value=Default value />

</asp:DropDownList>

4 Comments

Comments have been disabled for this content.