Sibusiso Shongwe Sibusiso Shongwe - 1 year ago 99
ASP.NET (C#) Question

How to Remove the selected index of a DropDownList?

I have an ASP.Net web for that inserts values into a database, I want to reset the selected items in the dropdownList, how do I do it properly?? I know with textBoxes I can use

TextBox1.Text = String.empty
but it doesnt seem to work with the dropdownLists

Answer Source

For DropDownList it would be better to first add an empty string at first position of the DropDownList by using yourDropDownList.Items.Insert method and then select it. Something like this:

yourDropDownList.Items.Insert(0, new ListItem(string.Empty, string.Empty));
yourDropDownList.SelectedIndex = 0;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download