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

I am looking for a solution for my problem. I am using two dropdownlist in my project. Assume one is ddlItemCode and the other is ddlItemName. Here the user can select from both Itemcode or ItemName . If he select an item from ddlItemCode the corresponding Itemname will be load in the ddlItemName.And if he select the item from ddlItemName the corresponding Itemcode will be loaded in the ddlItemCode. It is easy when we use normal dropdownlist . But here I have to use the cascading dropdownlist . It will be possible i Know. Here if i select an ddlItemCode it will load the corresponding item in the ddlItem. But it will only load the selected items name (only that item name will be in the dropdown, no other). I want all of the items should be loaded and the selected Item should display in the ddlItem. Is that possible? If yes How ? It will be helpfull if any one of you share the code for the above requirement.

If the question above isn't completely clear, please reply with a comment and I will be happy to provide the extra information.

Thanks a lot in advance
Posted
Updated 5-Nov-10 5:28am
v2

1 solution

If I understood you right, look into this example:

1. aspx file:

<asp:DropDownList runat="server" ID="ddlItemName" AutoPostBack="true"
           onselectedindexchanged="ddlItemName_SelectedIndexChanged">
           <asp:ListItem Text="Item1" Value="1"></asp:ListItem>
           <asp:ListItem Text="Item2" Value="2"></asp:ListItem>
           <asp:ListItem Text="Item3" Value="3"></asp:ListItem>
           <asp:ListItem Text="Item4" Value="4"></asp:ListItem>
       </asp:DropDownList>
       <asp:DropDownList runat="server" ID="ddlItemCode" AutoPostBack="true"
           onselectedindexchanged="ddlItemCode_SelectedIndexChanged">
           <asp:ListItem Value="Item1" Text="1"></asp:ListItem>
           <asp:ListItem Value="Item2" Text="2"></asp:ListItem>
           <asp:ListItem Value="Item3" Text="3"></asp:ListItem>
           <asp:ListItem Value="Item4" Text="4"></asp:ListItem>
       </asp:DropDownList


2. aspx.cs file:

public partial class Dropdowns : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void ddlItemName_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddlItemCode.SelectedValue = ddlItemName.SelectedItem.Text;
    }
    protected void ddlItemCode_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddlItemName.SelectedValue = ddlItemCode.SelectedItem.Text;
    }
}
 
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