문제

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.

도움이 되었습니까?

해결책

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"));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top