Thursday, August 21, 2008

How to Add static item to the top of DropDownList ASP.NET Web Control after biniding it

Sometimes you need to add a static item to the top of DropDownList ASP.NET Web Control, Such as "----" or "Select" or any other text.

If you add it in the design time you would see it but when you run the web site this item would be removed and replaced with the items that comes from the Data Source that you are using for binding.

In order to keep the static item, set the "AppendDataBoundItems" property of the DropDownList to "True".

Source: https://www.nilebits.com/blog/2007/10/add-static-item-to-dropdownlist-web-control-after-data-bind-in-asp-dot-net/

3 comments: