Sibusiso Shongwe Sibusiso Shongwe - 1 month ago 19
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

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;
Comments