Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to bind one dropdownlist to other drpdown list
Posted
Comments
Sandeep Mewara 30-Jun-12 6:49am    
Wb or winforms?

1 solution

Try this :
Make First Dropdown box Autopost Back Property True:

 private void FillDropDownList1()
    {

        DataSet ds = new DataSet();
        SqlDataAdapter myda = new SqlDataAdapter("select field1 from tablename",connection;
        myda.Fill(ds);
        dr1.items.clear(); //added
        dr1.DataSource = ds;
        dr1.DataTextField = "field1"; //added
        dr1.DataValueField = "field1";
        dr1.DataBind();

    }

put this on Page load:
        if (!IsPostBack)
        {
             FillDropDownList1();
        }

now, double click on first dropdown:

    protected void dr1_SelectedIndexChanged(object sender, EventArgs e)
    {
              DataSet ds = new DataSet();
        SqlDataAdapter myda = new SqlDataAdapter("select field1 from tablename where column1='"+dr1.selectedItem.value+"'",connection;
        myda.Fill(ds);
        dr2.items.clear(); //added
        dr2.DataSource = ds;
        dr2.DataTextField = "field1"; //added
        dr2.DataValueField = "field1";
        dr2.DataBind();

    }

this will surely help you. otherwise post it.
 
Share this answer
 
v3
Comments
AshishChaudha 30-Jun-12 6:49am    
my 5!
[no name] 30-Jun-12 6:53am    
thnks brother

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