Cannot have multiple items selected in a DropDownList.
Posted by Sebastien Lachance on March 8, 2008
Cannot have multiple items selected in a DropDownList.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Cannot have multiple items selected in a DropDownList.
Source Error:
I spent at least one hour figuring this out. The Source Error does not contain any valid information. The solution is : you should never use the same item twice on two different dropdownlist.Line 253: total = parseFloat(lblTotal.innerHTML.replace('$', '').replace(',', '.'));
Line 254: fBudget = parseFloat(budget.replace('$', '').replace(',', '.'));
Line 255: var lblWarningContract = document.getElementById('<%= lblWarningContract.ClientID %>');
Line 256:
Line 257: if (total > fBudget)
ListItem item = new ListItem(" -- Select one -- ", "-1"); ddlLoadingContact.Items.Insert(0, item); ddlUnloadingContact.Items.Insert(0, item);
A ListItem have a property called Selected that tells which one (the item) the dropdownlist should display as selected. If you use the same ListItem in more that one dropdownlist and you select this item in the DropDownA and a different item in DropDownB. The DropDownB will have two ListItem with the Selected property set to true. Since this is the same item in both dropdownlist.
ddlLoadingContact.SelectedValue = "-1"; //item will have the Selected property set to true ddlUnloadingContact.SelectedValue = "John"; //another item will have the Selected property set to true. And both are contained in this dropdownlist.

April 14, 2008 at 5:35 am
thanks a LOT!
I’ve spent whole day debugging and google’ing without success.
April 14, 2008 at 6:53 am
You are welcome!
May 22, 2008 at 9:47 pm
Thanks for the post it was very useful
July 22, 2008 at 6:53 am
it’s very helpful, THX a lot!!!!!!!!
I spent a day wonder around…………