更新时间:2023-12-04 20:31:10
没有需要循环的项目,只要找到该项目,并删除它:
No need to loop the items, just find the item and remove it :
ListItem itemToRemove = myDropDown.Items.FindByValue("value");
if (itemToRemove != null)
{
myDropDown.Items.Remove(itemToRemove);
}
或者,如果你知道要删除的项的索引,使用方法RemoveAt移除:
Or if you know the index of the item to remove, use RemoveAt method :
myDropDown.Items.RemoveAt(0);
但是,如果你想反正循环,这里是循环:
But if you want to loop anyway, here is the loop :
foreach (ListItem item in myDropDown.Items)
{
// your stuff
}