ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

You may receive the error "Cannot have multiple items selected in a DropDownList." when trying to set a value selected in an ASP.NET Dropdownlist.

This error specifically occurs if you are trying to execute a similar code as follows:-



DropDownList1.Items.FindByValue("3").Selected = true;

(or)

DropDownList1.Items.FindByText("Sports").Selected = true;

This error doesnt occur if you try to use

DropDownList1.SelectedIndex = 3;
or
DropDownList1.SelectedItem.Value = "3"; (Wrong way of implementation. But people use this)


The resolution is that, you just have to mention DropDownList1.ClearSelection(); before using D
ropDownList1.Items.FindByValue("3").Selected = true;

The correct step is as below:-

DropDownList1.ClearSelection();
DropDownList1.Items.FindByValue("3").Selected = true;

or

DropDownList1.ClearSelection();
DropDownList1.Items.FindByText("Sports").Selected = true;

In my next article I will discuss on the common misconception in making a particular Dropdownlist value selected.

Cheers and Happy Programming !!!

posted @ Wednesday, May 03, 2006 9:00 AM

Print

Comments on this entry:

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by john michel at 2/27/2007 11:05 AM
Gravatar
this info was very useful to me

thanks for ur information

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Lee Stevens at 3/1/2007 3:58 PM
Gravatar
cheers been bugging me that one!

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Bill Kuhn at 3/9/2007 9:09 PM
Gravatar
That solved a baffling error for me. Thanks!

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Ramy at 11/28/2007 8:09 AM
Gravatar
Thanks!!! You saved a food few hours!!!!

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Shail at 12/12/2007 1:41 AM
Gravatar
Thanks,
We searched for that problem on Google and found at top. Nice Solution.
Good work,
Keep it up :)

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Praveena at 12/17/2007 5:20 PM
Gravatar
This article was very useful to me and it is easily understandable

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Hitz at 2/13/2008 9:58 PM
Gravatar
Nice one. Saved my time. Cheers mate.

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Shaik at 2/18/2008 6:12 PM
Gravatar
Thanks. It helped me a lot.

Regards,
Shaik.

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Sankar at 2/25/2008 4:22 PM
Gravatar
Thanks..... i got an idea ....but what about it comes in master page not using FindByValue or text

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Eknath at 2/28/2008 4:24 PM
Gravatar
Ekdam Rapchik ha!

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Sfinx at 3/10/2008 3:04 AM
Gravatar
Straight forward solution thnx

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by rishian at 4/2/2008 4:48 PM
Gravatar
Thanks For The Help!! God Bless!

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by carlos at 5/5/2008 4:19 AM
Gravatar
Thanks very much for the solution!

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by abhishek at 5/8/2008 10:56 PM
Gravatar
thanks for the help

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Ravi Gupta at 5/9/2008 5:07 PM
Gravatar
i had spend almost 3-4 hours to this error. After that the solution you had given, solved my problem
Thank you very much

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Ashberger at 5/22/2008 7:57 PM
Gravatar
tnks you saved some debugging ours for me!!

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Kalaravi at 6/20/2008 12:43 AM
Gravatar
Thank you so much..this is really useful.....

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by sivaani at 6/30/2008 9:56 PM
Gravatar
thanks a lot nice solution

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Subhash at 7/7/2008 5:41 AM
Gravatar
this saved a lot of time for me !!! nice post

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Ashish at 7/15/2008 8:26 PM
Gravatar
got my problem solved in seconds.

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by chan myie at 7/29/2008 7:43 PM
Gravatar
thank for good article

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Sunitha at 8/10/2008 4:38 PM
Gravatar
Thank you,got my problem solved in seconds.

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Shailesh at 8/27/2008 12:33 AM
Gravatar
Thank you very much

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Pradeep at 9/20/2008 4:39 AM
Gravatar
Thanks a lot for the information. It was very useful!

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Mohit at 10/5/2008 10:22 AM
Gravatar
Thanks a lot. This is a great piece of information.

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by NIkeeta at 10/30/2008 6:36 PM
Gravatar
Thank u it helped me...

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Larrr at 11/3/2008 2:48 PM
Gravatar
Thnx, very useful as well! :o)

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Naved at 11/4/2008 12:13 PM
Gravatar
I tried this.. but i am getting another Error:

Object reference Not set to an instance of an Object

Pls help

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by kaaki at 11/6/2008 1:39 AM
Gravatar
haa.. thank u... saved a lot of time...in debugging..

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Just a VB Guy at 11/22/2008 1:58 AM
Gravatar

To avoid "Object reference Not set to an instance of an Object":

DropDownList1.ClearSelection()

dim li as listitem = DropDownList1.Items.FindByValue(3)

if li isnot nothing then
li.selected = true
end if

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by MarkJaL at 11/26/2008 5:18 PM
Gravatar
Hi
Another possibility is that you are using the same listItem instance multiple times. In my code I was declaring one ListItem:

ListItem listItemSelect = new ListItem("Select", "0");

and adding this to multiple dynamicly created dropdowns. If no selection is made on more than one dropwdown and the page is posted back, and you re-create the dropdowns then the listitem above is the selected item for those dropdowns - thus causing the same error.

So you don't necessarily have to clear the selection - first ensure you're not using the same listitem in multiple dropdowns.

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Cheryl at 12/11/2008 3:26 PM
Gravatar
Fantastic!!

Worked a treat, thanks!!

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Vijaycanaan at 12/12/2008 12:51 PM
Gravatar
This article greatly solved the problem which I was facing. Thanks a lot

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Snehal at 1/16/2009 4:18 PM
Gravatar
A gr8 help for me!!!!! Thanks

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Rama charan at 1/20/2009 4:54 PM
Gravatar
thansk a lot it saved me a lot of time

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by erwin at 2/5/2009 5:12 AM
Gravatar
Didn't work for me until I read the comment posted by MarkJal. Was using the same listItem instance in multiple dropdowns. Very helpful.

Thanks, saved me a lot of time and trouble.

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Gurdeep Singh at 4/13/2009 10:00 PM
Gravatar
Thank u so much :) it solved my problem i was struggling with too long. Yes it was a top link on google. Thanks again

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Sandeep Tanwer at 4/15/2009 9:56 AM
Gravatar
Thank u so much :) it solved my problem i was struggling with too long. Yes it was a top link on google. Thanks again

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Gowtham at 4/24/2009 2:51 AM
Gravatar
U R D Man! Thanks!

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Dave at 5/1/2009 2:44 AM
Gravatar

Strangely, this did not fix the problem for me:

The code I am using is:

ddState.ClearSelection();
ddState.Items.FindByValue("NM").Selected=true;

Thanks,
Dave

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Dave at 5/1/2009 2:46 AM
Gravatar
I found the solution for my delimna:

http://sebastienlachance.com/2008/03/08/cannot-have-multiple-items-selected-in-a-dropdownlist/

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Aalap at 5/6/2009 12:03 PM
Gravatar
Hey thanks man..that was a great help for me.

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Lo0 at 5/27/2009 4:17 PM
Gravatar
MarkJaL!!! Thank you :D

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Manesti at 6/1/2009 5:39 AM
Gravatar
God bless you, thank you. it was mosthelpful

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by PC at 6/3/2009 2:20 AM
Gravatar
I followed the above, and still had the problem. Turned out that the issues was because of the way I was adding an additional item to the databound dropdown.

.Insert will always give you this error in this situation. Instead use .Add to add additional ListItem. In 2.o you can leverage property AppendDataBoundItems="true"

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Harish Ranganathan at 6/30/2009 1:57 AM
Gravatar
Harish Ranganathan

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by saravanan at 8/3/2009 6:41 AM
Gravatar
it's v good .it' was a great help for me.

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Steel at 8/5/2009 11:10 PM
Gravatar
Thanks man... it was really helpful

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Paul van Tonder at 8/17/2009 5:57 AM
Gravatar
Thanks dude, i had to play with the idea a bit ...

For all who didnt find it helpful - yet - please remember to change your code to

dropdownlist1.Items.FindByText(*TextHere*).selected = true;

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Rahzam at 8/23/2009 3:25 AM
Gravatar
Thanks MarkJaL. I was using same instance in multiple drop downs. I didn't need to clear. I just make new instance and it worked

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by liki at 9/3/2009 6:36 AM
Gravatar
i got my solution. thanks

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Phillip Quinlan at 9/10/2009 3:47 PM
Gravatar
Ah, that worked - thanks a lot : )

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Ram at 9/17/2009 12:23 AM
Gravatar
Very Thanks Man.........Please Continue this way

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Leo 26 at 9/29/2009 11:43 PM
Gravatar
Its a good article indeed, very precise. I am facing a different problem with this error message. I am having a javascript calender control, and this error is showing on that control.
Can someone please suggest a possible solution.
Thx.

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by sandeep kumar trivedi at 9/30/2009 9:33 PM
Gravatar
it is very helpful for me.
Thx

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by DD at 10/13/2009 7:23 AM
Gravatar
thnks helped lot

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Gangatha at 11/10/2009 6:50 PM
Gravatar
Gr8 stuff. been struggling with this for a day.

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Kike at 11/12/2009 4:15 AM
Gravatar
Great! You Save my day!!

One question why this:

DropDownList1.SelectedIndex = 3;
or
DropDownList1.SelectedItem.Value = "3";

Are wrong solutions???

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by Suraj at 11/19/2009 12:22 AM
Gravatar
Excellent Tut.
God bless.

# re: ASP.NET Dropdownlist - "Cannot have multiple items selected in a DropDownList."

Left by raj at 11/20/2009 2:41 AM
Gravatar
thanks for ur information

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345