Reputation: 563
Can you please give me a clue how to do this? I have a DropDownList
, that DropDownList
is filled with ListItems
. After the DropDownList
, there's a Button
called ADD NEW. When the button is clicked, a popup opened. If an item is not in the DropDownList
, I wanted to add it. In popup box window there's a TextBox
and add Button
.
Basically, If an item is not in DropDownlist
I want to add it by clicking the ADD NEW button.
Upvotes: 0
Views: 1550
Reputation:
In popup when you enter the item and press add button just do the following steps:
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);
Upvotes: 1
Reputation: 223247
Something on the following line...
string newItem = textbox1.Text;
if(ddlMyList.Items.FindByText(newItem) == null) //Means item not found
{
ddlMyList.Items.Add(new ListItem(newItem));
}
Upvotes: 1