How To Add Item to DropDownList After DataBind in ASP.NET

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 --");

Post a Comment

Please do not post any spam link in the comment box😊

Previous Post Next Post

Blog ads

CodeGuru