且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当我点击另一个下拉列表时,如何从一个下拉列表中删除所选项目

更新时间:2023-11-29 23:47:40

 ListItem itm = dropdownlist2.Items.FindByValue(firstdropdownlistValue); 
if (itm!= null
{
dropdownlist2。 Items.Remove(ITM);
}


  int  count = DropDownList。 Items.Count  -   1 ; 
for int i = count; i > 0 ; i--)
DropDownList.Items.RemoveAt(i);


 ListItem itemToRemove = myDropDown.Items.FindByValue(value); 
if(itemToRemove!= null)
{
myDropDown.Items.Remove(itemToRemove);
}
或者如果您知道要删除的项目的索引,请使用RemoveAt方法:

myDropDown.Items.RemoveAt(0);


I am using 2 dropdownlist in which i added same items....wen i click item in 1st dropdownlist i want that particular item not to be displayed in the second dropdownlist...plz help regarding this....



Regards

Manohara r

ListItem itm=dropdownlist2.Items.FindByValue(firstdropdownlistValue);
if(itm!=null)
{
dropdownlist2.Items.Remove(itm);
}


int count = DropDownList.Items.Count - 1;
for (int i = count; i > 0; i--)
    DropDownList.Items.RemoveAt(i);


ListItem itemToRemove = myDropDown.Items.FindByValue("value");
if (itemToRemove != null)
{
    myDropDown.Items.Remove(itemToRemove);
}
Or if you know the index of the item to remove, use RemoveAt method :

myDropDown.Items.RemoveAt(0);