Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I have multiple drop downs, that all show the same values. When I select a particular item from one drop down, I want that selected item to be excluded from the next drop down.
How can I do that?

Thanks with Regards,
Amit
Posted
Updated 29-Jun-10 2:38am
v2
Comments
Rob Branaghan 29-Jun-10 8:00am    
So basically you have 3 or more drop downs with values 'A,B,C,D,E,F,G'

You want Each drop down to show 'A,B,C,D,E,F,G'.

But, when selecting a value (Lets say 'D') in the first Drop Down, you want the other 2 drop downs to show 'A,B,C,E,F,G'?

Is that what you are asking for?
Johnny J. 29-Jun-10 8:39am    
Edited your text slightly, Amit, because it doesn't look like your keyboard has any Shift key (to produce capital letter) - or Question Mark key for that matter... :)

Sandeep Mewara is right.There are two Drop down list

I have done it using First method. the code is like this at aspx page

ASP
<asp:dropdownlist id="ddl1" runat="server" autopostback="True" onselectedindexchanged="ddl1_SelectedIndexChanged" xmlns:asp="#unknown">
   <asp:listitem>A</asp:listitem>
   <asp:listitem>B</asp:listitem>
   <asp:listitem>C</asp:listitem>
   <asp:listitem>D</asp:listitem>
   <asp:listitem>E</asp:listitem>
</asp:dropdownlist>
                
<td>
   <asp:dropdownlist id="ddl2" runat="server" xmlns:asp="#unknown">
      <asp:listitem>A</asp:listitem>
      <asp:listitem>B</asp:listitem>
      <asp:listitem>C</asp:listitem>
      <asp:listitem>D</asp:listitem>
      <asp:listitem>E</asp:listitem>
   </asp:dropdownlist>
</td>




At aspx.cs page

C#
protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
{
    ddl2.Items.Remove(ddl1.SelectedItem);
}

You can enhance the code according to your desired need

[From WW: next time you want to post code, use the pre tags. They format the code like I'm sure you've seen on here and make it much easier to read. Also, just take a little time to fix the extra spaces from when you pasted it in. An extra few seconds can really make the answer much more readable.]
 
Share this answer
 
v3
Comments
William Winner 29-Jun-10 12:30pm    
Reason for my vote of 5
what I would have said...
Two options:
1. have a postback (partial or full). Filter that value from other dropdowns. (filter as in, remove that specific value)
2. have it handled client side using Javascripts. have a onchange handler on them. In onchange method remove the selected value from other dropdowns.

Try any one that suits you. (I would go for second option!)

BTW, if the dropdwons are dependent then i would not fill all from start, instead i will fill them as an when the previous one is selected.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900