- protected void Page_Load(object sender, EventArgs e)
- {
- // Why this code Load in Page_Load
- if (!Page.IsPostBack)
- {
- SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");
- SqlCommand cmd = new SqlCommand("select * from tbl_country", con);
- SqlDataAdapter sda = new SqlDataAdapter(cmd);
- DataTable dt = new DataTable();
- sda.Fill(dt);
- DropDownList1.DataSource = dt;
- DropDownList1.DataBind();
-
- }
// end Why this code Load in Page_Load
-
- }
- protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
- {
- DropDownList2.Items.Clear();
- DropDownList2.Items.Add("Select State");
-
- SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");
- SqlCommand cmd = new SqlCommand("select * from tbl_state where country_id=" + DropDownList1.SelectedItem.Value, con);
- SqlDataAdapter sda = new SqlDataAdapter(cmd);
- DataTable dt = new DataTable();
- sda.Fill(dt);
- DropDownList2.DataSource= dt;
- DropDownList2.DataBind();
- }
- protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
- {
- DropDownList3.Items.Clear();
- DropDownList3.Items.Add("Select State");
-
- SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");
- SqlCommand cmd = new SqlCommand("select * from tbl_city where state_id=" + DropDownList2.SelectedItem.Value, con);
- SqlDataAdapter sda = new SqlDataAdapter(cmd);
- DataTable dt = new DataTable();
- sda.Fill(dt);
-
- DropDownList3.DataSource = dt;
- DropDownList3.DataBind();
-
- }