Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have created three drop down list lists in which if i have selected one from the 1st drop down list then the one which i selected should not display in the second list i.e., except the one which i selected should be displayed in the second as the same with the 3rd one also
i am doing this in asp.net....

plz help me fast
Posted
Updated 24-Aug-12 0:23am
v2
Comments
[no name] 24-Aug-12 6:23am    
not clear whay you sayyy.. please give some brief....
vaibhav mahajan 24-Aug-12 6:24am    
i agree with Mits Machhi..
Prasad_Kulkarni 24-Aug-12 6:31am    
Post code snippets if possible.
pradiprenushe 24-Aug-12 6:37am    
I think you should use listbox or dropdown with multiple selection rather than this logic.
Legor 24-Aug-12 7:05am    
Please improve the question with more details.

I think you're saying you want three lists, and they should all have a different selection, so whichever one is in one list, selected, is not in the others. This is easy to do, if you create a list in memory. When the selection of one changes, you repopulate the others, making sure you first store so you can again set the selection. But, as others said, this is horrible UI.

A web site I work on did this, and in our case, there were three boxes, and three options, the idea was that each had to be selected once, to set an order. I used JQuery UI[^] to replace this with a drag and drop list. If you have more than three items and this is not good UI, then I agree that one single multiselect list is way better as a way of doing this. Or you could do a drag and drop between two lists, so the second always has no more than three items, and must have three, to select the three you need.

This[^] also seems like a good option.
 
Share this answer
 
Judging by the Issue you are having and the fact that you might be inexpereinced with asp.net ,

1)turn on autopostback on your dropdowns
2)if your lists gets populated from your code behind ensure that you only pupulate the first list on if(!IsPostback)
3) You can implement ajax but this adds complexity


Hope this finds you in tiem to help
 
Share this answer
 
v2
 
Share this answer
 
Here is the code given. If find solution mark as answer.

.aspx page : Suppose you have 2 dropdownlist

XML
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
            onselectedindexchanged="DropDownList1_SelectedIndexChanged">
            <asp:ListItem>Item1</asp:ListItem>
            <asp:ListItem>Item2</asp:ListItem>
            <asp:ListItem>Item3</asp:ListItem>
            <asp:ListItem>Item4</asp:ListItem>
            <asp:ListItem>Item5</asp:ListItem>
        </asp:DropDownList>
        <br />
        <asp:DropDownList ID="DropDownList2" runat="server">
        </asp:DropDownList>


Code Behind :-

C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList2.Items.Clear();
        foreach (ListItem li in DropDownList1.Items)
        {
            if (li.Text != DropDownList1.SelectedItem.Text)
            {
                DropDownList2.Items.Add(li);
            }
        }
    }
 
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