Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.net DropDownList with no selected item

I have a ASP DropDownList with items added to it. All what I want is to make the selection after the page loaded empty so there is no a selected item.

How can I do that?

like image 661
Eyla Avatar asked Feb 08 '10 20:02

Eyla


1 Answers

If the dropdownlist is being populated by DataSource, is important do the DataBind before the insert. Otherwise the item insertion does not happen.

myDropDown.DataBind();
myDropDown.Items.Insert(0, new ListItem(string.Empty, string.Empty));
myDropDown.SelectedIndex = 0;

https://stackoverflow.com/a/2224636/1467453

like image 152
Marco Castelo Avatar answered Nov 26 '22 02:11

Marco Castelo