打开按钮单击弹出窗口时带按钮的下拉列表

时间:2012-06-20 11:41:23

标签: c# asp.net c#-4.0 webforms

你能告诉我怎么做这个吗?我有一个DropDownListDropDownList填充了ListItems。在DropDownList之后,有一个名为 ADD NEW Button。单击该按钮时,会打开一个弹出窗口。如果某个项目不在DropDownList中,我想添加它。在弹出框窗口中有一个TextBox并添加Button

基本上,如果某个项目不在DropDownlist我想通过点击添加新按钮来添加它。

2 个答案:

答案 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);