Click here to Skip to main content
15,923,087 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Experts !!

am working on asp.net,C#,Sqlserver2005

I have Two Dropdownlists.... Dropdownlist1 and Dropdownlist 2

In first dropdownlist it shows list of companies..... in second dropdownlist it shows Departments.

These two will comes from database.

Suppose when the user select the company from 1st dropdownlist so,in the other dropdownlist it should show related departments to that company.

Please help me how to do this.

Thanks.
Posted

you can use following things:
C#
protected void Page_Load(object sender, EventArgs e)
   {
        
        if (!IsPostBack)
        {
             FillDropDownList();
        }
    }     

Make company drop down Auto postback true.
private void FillDropDownList()
      {
          DataSet ds = new DataSet();
          SqlDataAdapter myda = new SqlDataAdapter("Select company  FROM Tablename", connection Object);
     myda.Fill(ds);
     drop_company.DataSource = ds;
     drop_company.DataValueField = "company";
     drop_company.DataBind();
     drop_company.Items.Insert(0, new ListItem("Select", "0"));
 }

Double click on Company`s DropDown.
protected void drop_company_SelectedIndexChanged(object sender, EventArgs e)
   {

       DataSet ds = new DataSet();
       SqlDataAdapter myda = new SqlDataAdapter("Select department FROM tablename where company='"+drop_company.SelectedItem.Value+"'",connection_Object);
       myda.Fill(ds);
       drop_dept.DataSource = ds;
       drop_dept.DataValueField = "department";
       drop_dept.DataBind();
       drop_dept.Items.Insert(0, new ListItem("Select", "0"));

   }


Hope This will Help You, if not please Post it.
 
Share this answer
 
v2
 
Share this answer
 
v2
Comments
panduu 29-Jul-12 15:58pm    
Thanks a lot.
It should be uderstandble

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