Setting a default list item in a drop down list

Ever wanted to add a default “select” item to a listbox after a databind?
The following should do the trick.


DropDownList1.DataSource = YourDataSet;
DropDownList1.DataBind();

// Add Default list item at index 0
DropDownList1.Items.Insert(0, new ListItem("- select -", "0"));

This adds a new item with a text title of “- select -” and a value of 0.

Did you like this? Share it:

No related posts.



Leave a Reply

You must be logged in to post a comment.