【问题标题】:Dropdownlist with button when button click popup opened按钮单击弹出窗口打开时带有按钮的下拉列表
【发布时间】:2023-03-26 05:37:02
【问题描述】:

你能告诉我如何做到这一点吗?我有一个DropDownList,那个DropDownList 充满了ListItems。在DropDownList 之后,有一个Button,称为添加新。单击按钮时,会打开一个弹出窗口。如果某个项目不在DropDownList 中,我想添加它。在弹出框窗口中有一个TextBox 并添加Button

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

【问题讨论】:

  • @TimSchmelter 我要写那个代码,但在此之前我已经问了正确的方向。不是代码

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


【解决方案1】:

下面一行的内容...

string newItem = textbox1.Text;
if(ddlMyList.Items.FindByText(newItem) == null) //Means item not found
    {
    ddlMyList.Items.Add(new ListItem(newItem));
    }

【讨论】:

    【解决方案2】:

    当您输入项目并按下添加按钮时,在弹出窗口中只需执行以下步骤:

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

    【讨论】:

      猜你喜欢
      • 2018-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多