Digital Colony!

Add Item to DropDownList After DataBind

We often want the first option in a drop-down list to not default to the first item in the list. Instead we would prefer the option of adding a --Select Item-- at the top of the asp:DropDownList. After the DataBind, execute an Item.Insert.
ddlAuthor.DataTextField = "FullName";
ddlAuthor.DataValueField = "AuthorID";
ddlAuthor.DataSource = authorDB.GetAuthors();
ddlAuthor.DataBind();
ddlAuthor.Items.Insert(0, "-- Select Author --");

Labels: ,

posted by MAS on Mar 30,2007

Legacy Comments

If you found this site helpful, consider buying me a cup of coffee. Smile

Digital Colony Copyright © 1999-2010 XHTML   508
Try...Catch Disclaimer: For brevity many examples do not include error handling. That is your responsibility.