Dynamically Populating Drop Down Lists

B

ben

Hi All,
I have 3 dropdown lists which function as filters for the data being
passed into a datagrid...On Page load, the first drop downlist
populates with relevant data(using sql query), n now, depending on the
selection of the first drop down list, corresponding values get
populated into the second drop downlist, sort of like country, state,
city hierarchy...n depending on the selected index on 2nd, the 3rd ddl
gets populated, n then the datagrid is formed with that data....I have
tried placing the code to populate the second DDL in the
selectedindexchanged even of the first DDL and it does not work as
expected, i also have autopostback set to true so that it looks
dynamic to the user...this is some of the code(ddlcountry is the first
DDL

public void ddlcountry_SelectedIndexChanged(object sender,
System.EventArgs e)
{ string connstr=ConfigurationSettings.AppSettings["ConnectionString"];
string selectext="select ....where
g.cCountryID="+ddlcountry.SelectedItem.Value;
SqlConnection con1=new SqlConnection(connstr);
Response.Write(selectext);
SqlCommand mycommand2=new SqlCommand(selectext,con1);
con1.Open();
SqlDataReader dr1= mycommand2.ExecuteReader();

ddlstate.DataSource=dr1;
ddlstate.DataTextField="state";
ddlstate.DataValueField="cStateID";
ddlsubgroup.DataBind();
con1.Close();
dr1.Close();

}

Any help will be greatly appreciated !
Thanks in advance,
Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top