I have a drop down list in ASP.NET.
I want to remove every item from this list apart from the first one.
I see there is a Remove methond on items but it dosn't seeem to meet my needs.
Can this be done?
Here is the code for the clear method:
var listItem = DropDownList.Items[0];
DropDownList.Items.Clear();
DropDownList.Items.Add(listItem);
you could grab the first element and store it in a local variable, then remove all items (Clear method) and finally add the first element again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With