DropDownList SelectedIndex Problem

session101

Member
Joined
May 10, 2006
Messages
23
After I add item to a DropDownList, .NET automatically selects the first item for me. How do I default a blank/No Value for this DropDownList?

I tried to make the selectedindex = -1, but it does not seem to work using C# as the language for ASP.NET. Please advise. Thanks!
 
Youll have to add a blank value to your dropdownlist. This is typically the first entry, but doesnt have to be - you can set the SelectedValue or SelectedIndex to match the blank.

If youre using ASP.NET 2.0 and binding your dropdown then you can take advantage of the new AppendDataBoundItems property. In the page you can specify one blank entry with:
<asp:ListItem Value="" Text=""/>

Then on the dropdownlist itself, set AppendDataBoundItems to true. When you add the code to bind the dropdownlist, the new items will be appended after the blank value.

If youre using ASP.NET 1.x, Ive traditionally added the blank to my datasource when doing binding.

If youre not binding, then just add the blank :)

-ner
 
Back
Top