[RESOLVED] Setting asp:dropdownlist to ""
I have an asp:DropDownList control on one of my forms. When the page loads it contains the 1st value in the list. I know in VB.Net you can set the "SelectedIndex" property to -1 which leaves the control empty upon load. However, I tried doing that with the asp control and it didn't work. How is it done in ASP.Net?
Thanks,
Re: Setting asp:dropdownlist to ""
Hey,
Are you binding the DropDownList with Data from somewhere else?
If so, on the DataBound event of the DropDownList, add some code to add another blank entry to the DropDownList.
Something like:
Code:
DropDownList.Items.Insert(0, "")
Gary
Re: Setting asp:dropdownlist to ""
In web development, a dropdownlist (a select control) must have an item selected and so the browser defaults to the first if you don't select something yourself. Most devs get around this by introducing a "Please select one" item or a blank item.
Re: Setting asp:dropdownlist to ""
Gary,
I added that code in the DAtabound Event and that worked. Mendhak, the field in question is a 2 digit state code, therefore somekind of message would not look right.
Thanks guys,
Re: [RESOLVED] Setting asp:dropdownlist to ""
Hey,
Glad to hear you got it working!
Gary