Click here to Skip to main content
15,882,152 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have an application that needs two drop down list .one dropdown list contain item("Animal","Vehicle")and another dropdown list contains item ("cat","car").The second drop down list is invisible and doesn't contain item but if i select "animal" from dropdown list1 then it visible and show an item "cat".
Posted
Comments
subhra22 9-Sep-12 1:17am    
Please help me !!

 
Share this answer
 
Comments
__TR__ 9-Sep-12 3:45am    
Good Links. +5
Prasad_Kulkarni 10-Sep-12 0:04am    
Thank you TR!
Mohamed Mitwalli 9-Sep-12 4:05am    
5+
Prasad_Kulkarni 10-Sep-12 0:04am    
Thank you Mohamed!
ridoy 9-Sep-12 7:20am    
plenty of links for dropdownlist..+5
Hi ,
Check this
Dropdownlist[^]
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        DropDownList1.Items.Add("select");
        DropDownList1.Items.Add("Animal");
        DropDownList1.Items.Add("Vehicle");

    }
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (DropDownList1.SelectedIndex == 1)
    {
        DropDownList2.Items.Clear();
        DropDownList2.Visible = true;
        DropDownList2.Items.Add("cat");
    }
    else if(DropDownList1.SelectedIndex == 2)
    {
        DropDownList2.Items.Clear();
        DropDownList2.Visible = true;
        DropDownList2.Items.Add("car");
    }
    else if (DropDownList1.SelectedIndex == 0)
    {
        DropDownList2.Visible = false;
        DropDownList2.Items.Clear();
    }
}


XML
<div>
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
        onselectedindexchanged="DropDownList1_SelectedIndexChanged">
    </asp:DropDownList>
    <asp:DropDownList ID="DropDownList2" runat="server" Visible="False">
    </asp:DropDownList>

</div>


Best Regards
M.Mitwalli
 
Share this answer
 
Comments
__TR__ 9-Sep-12 3:45am    
5ed!
Mohamed Mitwalli 9-Sep-12 4:01am    
Thanks TR :)
ridoy 9-Sep-12 7:19am    
correct..+5
Mohamed Mitwalli 9-Sep-12 7:48am    
Thanks Ridoy
Prasad_Kulkarni 11-Sep-12 0:41am    
5'ed :D

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