Tuesday, November 6, 2012

Removing list items from the DropDownList

DropDownList1.Items.RemoveAt(0);
But if you want to loop anyway, here is the loop :
foreach (ListItem item in DropDownList1.Items) 
{ 
 // your condition

}
 
Or if you know the index of the item to remove, use RemoveAt method :


 
ListItem itemToRemove = DropDownList1.Items.FindByValue("value");
if (itemToRemove != null)
{
    DropDownList1.Items.Remove(itemToRemove);
}
 

No comments:

Post a Comment