asp.net: How can I remove an item from a dropdownl

2019-02-11 15:11发布

I have a dropdownlist, and in some cases need to remove an item (in the code-behind). I need to remove the item based on the value of the item.

How can I do this?

9条回答
冷血范
2楼-- · 2019-02-11 15:50

You can use the

myDropDown.Items.Remove(ListItem li);

or

myDropDown.Items.RemoveAt(int index);

to remove it using C#.

查看更多
放荡不羁爱自由
3楼-- · 2019-02-11 15:55

myDropDown.Items.Remove(myDropDown.Items.FindByText("Chicago"));

查看更多
Lonely孤独者°
4楼-- · 2019-02-11 15:56

I would add an identifying Id or class to the dropbox and remove using Javascript.

The article here should help.

D

查看更多
登录 后发表回答