Reputation: 2982
I am getting an error message "Cannot have multiple items selected in a DropDownList." After searching SO and google, I have narrowed the error cause to the ddlVendor.Items.Add(li) code block :
ListItem li = new ListItem();
string[] TransDetail = Trans[0].Split(',');
li.Text = TransDetail[0].ToString() + ", " + TransDetail[1].ToString();
//TransDetail[2] = VendorId;
//TransDetail[3] = TransId;
li.Value = TransDetail[2].ToString() + ", " + TransDetail[3].ToString();
//ddlVendor.Items.Add(li);
I have tried ClearSelection()
and .SelectedItem
but no luck.
Any ideas why the code block above would be causing an error?
Update: When I comment ddlVendor.Items.Add(li);
the page loads fine.
Is there another way to add an item to a dropdownlist box? I am using VS 2008.
Upvotes: 2
Views: 268
Reputation: 2982
The issue was resolved by changing the code to add items to the dropdown list (Add value manually into DropDownList, CheckBoxList and RadioButtonList.):
YourDropDownList.Items.Add(new ListItem("JAKARTA", "JKT"));
Upvotes: 1