Ian Boyd (above) had a great answer - add this to Ian Boyd’s WebExtensions class to select an item from the drop-down list based on text:
/// <summary> /// Selects the item in the list control that contains the specified text, if it exists. /// </summary> /// <param name="dropDownList"></param> /// <param name="selectedText">The text of the item in the list control to select</param> /// <returns>Returns true if the value exists in the list control, false otherwise</returns> public static Boolean SetSelectedText(this DropDownList dropDownList, String selectedText) { ListItem selectedListItem = dropDownList.Items.FindByText(selectedText); if (selectedListItem != null) { selectedListItem.Selected = true; return true; } else return false; }
To call it:
WebExtensions.SetSelectedText(MyDropDownList, "MyValue");
Dan B Feb 20 '14 at 19:37 2014-02-20 19:37
source share