session101 Posted May 16, 2006 Posted May 16, 2006 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! Quote
*Experts* Nerseus Posted May 16, 2006 *Experts* Posted May 16, 2006 You'll have to add a blank value to your dropdownlist. This is typically the first entry, but doesn't have to be - you can set the SelectedValue or SelectedIndex to match the blank. If you're 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 you're using ASP.NET 1.x, I've traditionally added the blank to my datasource when doing binding. If you're not binding, then just add the blank :) -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
session101 Posted May 16, 2006 Author Posted May 16, 2006 I was trying to avoid putting in the blank entry, but I'll do it. Thanks!!! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.