I need to clear drpAddressTypes dropdown values except the first item and bind again that dropdownlist.
drpAddressTypes.Items.Clear();
var lstAddressTypes = repository.GetAddressTypes(userId);
if (lstAddressTypes != null)
{
foreach (var item in lstAddressTypes)
{
var addressType = new ListItem(item, item);
drpAddressType.Items.Add(addressType);
}
}
When I am using drpAddressTypes.Items.Clear(); it is clearing all items.
How can I clear all items except the first item.
Thanks in advance. 🙂
You could retrive the firstitem and then clear the list and add the item again.