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

How to Remove the SelectedIndex of a DropDownList?

I have an ASP.NET Web Forms 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 doesn't 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;