DropDownList
,DropDownList
填充了ListItems
。在DropDownList
之后,有一个名为 ADD NEW 的Button
。单击该按钮时,会打开一个弹出窗口。如果某个项目不在DropDownList
中,我想添加它。在弹出框窗口中有一个TextBox
并添加Button
。
基本上,如果某个项目不在DropDownlist
我想通过点击添加新按钮来添加它。
答案 0 :(得分:1)
以下内容......
string newItem = textbox1.Text;
if(ddlMyList.Items.FindByText(newItem) == null) //Means item not found
{
ddlMyList.Items.Add(new ListItem(newItem));
}
答案 1 :(得分:1)
在弹出窗口中输入项目并按添加按钮时,只需执行以下步骤:
1. Iterate through all the elements in dropdown and check if item you want to add exist or not
2. If item does not exist then add it to dropdown using this code:
yourDropdown.items.Add(newitem);