Rami M. Nassar's Blog

Development, Beyound LifeStyle

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>

Comments

Jennifer said:

So-so. Something was not impressed.

# March 27, 2012 2:51 PM

Jennifer said:

So-so. Something was not impressed.

# March 27, 2012 2:51 PM

Rajashekaran said:

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

# May 28, 2012 4:36 AM

Spurlock said:

Unquestionably consider that which you said.

Your favourite reason seemed to be at that the web the easiest factor to be mindful of.

I say to you, I certainly discover irked even as other folks consider worries they just don’t be

acquainted with about. You controlled to hit the nail upon that

the highest and defined out that the entire thing without having side-effects , people

could take a signal. Will probably be back to seek out more.

Thanks

# December 25, 2012 9:05 PM
Thanks for sharing your feedback! If your feedback doesn't appear right away, please be patient as it may take a few minutes to publish - or longer if the blogger is moderating comments.