How to Search Through a C# DropDownList Programmatically
foreach (ListItem li in dropdownlist1.Items)
{
if (li.Value == textBox1.text)
{
// The value of the option matches the TextBox. Process stuff here.
}
}
That is my suggestion for how to see if the value is in the dropdownlist.
The DropDownList inherits the Items collection from the ListControl. Since Items is an Array, you can use this syntax:
dropdownlist1.Items.Contains(textbox1.Text) as a boolean.
You can simply do like this.
if (ddl.Items.FindByValue("value") != null) {
ddl.SelectedValue = "value";
};