Thursday, January 10, 2008

How do I change the default selected item of runtime data bounded ASP.NET DropDownList?

When you bind data to ASP.NET DropDownList at runtime, the default value will be the first data item of the returned dataset. So, by default we can see the selected data item of DropDownList. But what should we do, if we want to have non selected DropDownList or if I want to show text like “—Select—“at runtime.

With ASP.NET you can do it like below:

FAQ00010

Nothing big with above code. Just add what you want inside the DropDownList DataBound event and don’t forget to set the item index to zero. The other thing is here we insert the DropDownList item, not the adding.

Labels:

0 Comments:

Post a Comment

<< Home