Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Friends,

Have a Good Day !!

I have Two DROPDOWNLISTS on my Webform and I want to Bind Each Other.

Suppose if I select CollegeName from College Dropdownlist...and the Other one Should Display the Departments of that Particular College.
Please can u suggest me how to do this ?
Thanks in ADVANCE.
Updated 17-Jun-12 20:49pm
Pankaj Nikam 18-Jun-12 2:22am    
What have you tried till now? I mean can you put the code which does not work so we might find a problem and fix it?
Sandeep Mewara 18-Jun-12 2:40am    
I doubt if you are trying from a week. You are posting question consistently over here. If you got stuck a week back, I am sure you would have posted it earlier. Further, by now, you should know that sharing what you have done so far helps and gets more response. You posted what you need but failed to show your effort.

Hi Ranjeet,

I am sure u have done every thing right just you are missing few silly points.
Please follow the steps below i hope that will solve your problem
a) Bind the college dropdown with college fields in database.
dataset retCollegeName = objDAL.FillCmbCollegeName(objDataset);
cmbCollegeNAme.DataSource = retCollegeName.Tables["CollegeName"];
cmbCollegeNAme.DataTextField = "Name";
cmbCollegeNAme.DataValueField = "OrderSeq";
b) go to property of cmbCollegeNAme and set auto postback = true;
c) call a query to fetch department as same defined above from cmbCollegeNAme.SelectedIndexChanged and populate the Department dropdown in the same way as above.

Hope this will solve your problem
Amit Dutta
Share this answer
Try This :
make auto postback true Property for College Dropdown.

       if (!IsPostBack)


 private void FillDropDownList()
        DataSet ds = new DataSet();
        SqlDataAdapter myda = new SqlDataAdapter("Select college  FROM tablename",connection object);
        drop_college.DataSource = ds;
        drop_college.DataValueField = "college";
        drop_college.Items.Insert(0, new ListItem("Select", "0"));

then after double click on college Dropdown.

 protected void drop_college_SelectedIndexChanged(object sender, EventArgs e)
        DataSet ds = new DataSet();
        SqlDataAdapter myda = new SqlDataAdapter("Select department FROM tablename where college='"+drop_college.SelectedItem.Value+"'", connection object);
        drop_department.DataSource = ds;
        drop_department.DataValueField = "department";
        drop_department.Items.Insert(0, new ListItem("Select", "0"));

Hope this will help You.
Share this answer
where u got stuct. bind the second dropdownlist on first dropdownlist SelectedIndexChanged event. as described in solution 3.
Share this answer
Make sure the auto postback property be set true. This is used to trigger the SelectedIndexChanged event of the dropdownlist

Fill the data for your first dropdown and when the event invoked the code must be like this,

protected void drop_college_SelectedIndexChanged(object sender, EventArgs e)
        DataSet ds = new DataSet();
        SqlDataAdapter dataAdapter = new SqlDataAdapter("Select DepartmentName,DepartmentID FROM DepartmentTable where CollegeName='"+ddlCollegecollege.SelectedItem.Value+"'", connection object);
        ddlepartment.DataSource = ds;
        ddlDepartment.TextValueField = "DepartmentName";
        ddlDepartment.DataValueField = "DepartmentID"
        ddlDepartment.Items.Insert(0, new ListItem("-- Select Department --", "0"));

Hope it helps, Happy coding
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