Click here to Skip to main content
14,459,361 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,
I am having some number of Dropdownlists in asp.net. All are binding with same data.
For example Consider 1,2,3,4,5 are the listitems to the dropdownlists. When user selects 3 in any dropdownlist it should not available in remaining DDls. Same functionlaity for other dropdowns so that our selection should be unique.And if deselect 3 and selected 5 then 3 should available in remaining DDls. Please help me with any apporoach.
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

Use the OnSelectedIndex changed event. Remove the one selected item from the other DDL controls.
   
Comments
Member 7901586 6-Sep-12 9:25am
   
Hi Mattu,

for removing item from other ddls your solution is fine. but we have to add the item whenever user changed his selection.Lets consider first he selected 3 value in DDL1 then we removed 3 in all other DDLS. Then he changed his selection to 5 then 5 has to remove from other DDLS then 3 should add again in the same DDLs.
Rate this:
Please Sign up or sign in to vote.

Solution 2

Instead of having multiple dropdowns all populated with the same values, why not implement something like a checked multiselect dropdownlist?
https://github.com/scottwb/jquery.ui.dropdownchecklist[^]
The samples included in this library are very good. I've used this library extensively and it is a godsend to issues like what you are describing.
   
Comments
Member 7901586 6-Sep-12 10:40am
   
Hi Marcus,
Thanks for your suggestion. But my requirement doesn't fulfill with multiselect dropdownlist so that I have to assign the values of each DDl to the other variables.
fjdiewornncalwe 6-Sep-12 11:54am
   
I can see that. I've been in that situation as well. What you can maybe do is implement javascript that validates the selections being made in the dropdowns. If the user attempts to select an option that was selected in a previous dropdown then the selection is cancelled and the user notified. It is clunky, but the more elegant system of adding and removing items from each dropdown based on current selections might be a little overwhelming.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100