I am using the following to select have the dropdown list select an item from the list:
ddlIndustry.Items.FindByText(\"Trucking\").Selected = true;
This is what you want to do:
ddlIndustry.SelectedValue = ddlIndustry.Items.FindByText("Cards").Value;
The problem is that making ListItem
as Selected
does not clear selection of other ListItems. Keep in mind that Items
property is a ListItemColletion
, which is also used in ListBox
and CheckListBox
, which allow multiple item selection (while DropDownList
does not allow that, which is why you got the error).
Using the SelectedValue
propery of the DropDownList
takes care of the multi-selection for you, unselecting previously selected items and selecting the new item by value.
You can check for a correlated issue here: https://stackoverflow.com/a/16068632/570191
Try using ClearSelection
to clear previous selection:
ddlIndustry.ClearSelection();
if (ddlIndustry.Items.FindByText("Cards") != null)
ddlIndustry.Items.FindByText("Cards").Selected = true;