protected void Page_Load(object sender, EventArgs e) { if(DropDownList1.SelectedIndex > 0) BindDropDownList2(DropDownList1.SelectedItem.Text); } protected void Button2_Click(object sender, EventArgs e) { if (DropDownList1.SelectedIndex == 5) if (DropDownList2.SelectedIndex == 3) Label1.Text = "You selected index 5 from ddl1 and index 3 from ddl2"; } private void BindDropDownList2(string field) { if (DropDownList1.SelectedIndex != 5) { con.ConnectionString = strcon; com.Connection = con; con.Open(); string strQuery = @"SELECT " + DropDownList1.SelectedItem.Text + " FROM NUMS"; da = new SqlDataAdapter(strQuery, con); da.Fill(ds); DropDownList2.DataSource = ds; DropDownList2.DataTextField = field; DropDownList2.DataValueField = field; DropDownList2.DataBind(); con.Close(); } else { DropDownList2.Items.Clear(); DropDownList2.Items.Add(""); DropDownList2.Items.Add("A"); DropDownList2.Items.Add("B"); } }
protected void Page_Load(object sender, EventArgs e) { if(!isPostBack) { if(DropDownList1.SelectedIndex > 0) BindDropDownList2(DropDownList1.SelectedItem.Text); } }
if(isPostBack) return;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)