Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
the code is used is this ....plsss tell me the error in this...

protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
int countryId = int.Parse(DropDownList1.SelectedIndex.ToString ());
DataTable dt = new DataTable();
dt = bindDropDown("select countryid,countryname from tblcountry where tblcountry.regionid =" + countryId );
DropDownList1.DataSource = dt;
DropDownList1.DataValueField = "countryid";
DropDownList1.DataTextField = "countryname";
DropDownList1.Items.Insert(0, new ListItem("--Select--", "0"));


public DataTable bindDropDown(string query)
SqlDataAdapter dataAdapter = new SqlDataAdapter(query,con);
DataSet dataSet = new DataSet();
return (dataSet.Tables[0]);
in the form load event

if (!IsPostBack)
DataTable dt1 = new DataTable();
dt1 = bindDropDown("select tblregion.regionid,tblregion.regionfullname from tblregion");
DropDownList2.DataSource = dt1;
DropDownList2.DataTextField = "regionfullname";
DropDownList2.DataValueField = "regionid";
DropDownList2.Items.Insert(0, new ListItem("--Select--", "0"));
Updated 8-Feb-12 1:42am

1 solution

Share this answer
Espen Harlinn 8-Feb-12 9:22am    
Good link :)
Abhinav S 8-Feb-12 9:28am    
Thank you Espen.
amaljosep 9-Feb-12 2:20am    
yes...i got it......thanks a loooooot for the quick reply.......

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