View Single Post
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: populate two dropdownlist

 
0
  #7
Dec 3rd, 2007
Your code should work fine as is, you just need to give the Where Country_id= ... in the query so that it returns the states for that country.

  1. protected void dd1_SelectedIndexChanged(object sender, EventArgs e)
  2. {
  3. string countryid;
  4. countryid = dd1.SelectedValue;
  5. SqlConnection con = new SqlConnection("user id=sa;password=vubrain;database=raghu;data source=vubrain4");
  6. SqlDataAdapter da1 = new SqlDataAdapter(string.Format("SELECT stateid,statename FROM countrystate where country_id='{0}' ",countryid) );
  7. DataSet ds1 = new DataSet();
  8. da1.Fill(ds1, "countrystate");
  9. dd2.DataSource = ds1.Tables["countrystate"];
  10. dd2.DataTextField = "statename";
  11. dd2.DataValueField = "stateid";
  12. dd2.DataBind();
  13. }
Reply With Quote