请问如何实现dropdownlist的三级联动?
最近在自学 自己做一个小项目玩玩,用到dropdownlist的三级联动,不知道如何实现,请各位指点,谢谢!代码:
目的是从一张表中选出 "学院" 填充dropdownlist1,然后根据dropdownlist1的选择 从表中选出 "专业"填充dropdownlist2,再根据dropdownlist2的选择,从表中选出"班级" 填充dropdownlist3,但是好像每次回传之后dropdownlist1都是一样的,导致dropdownlist2也是一样..
protected void Page_Load(object sender, EventArgs e)
{
string strCon = "Data Source=.;" +
"Initial Catalog=studentManageSystem;" +
"Integrated Security=True;";
string strSQL = "select distinct academyName from academyCourse";
SqlConnection con = new SqlConnection(strCon);
con.Open();
SqlDataAdapter da = new SqlDataAdapter(strSQL, con);
DataSet ds = new DataSet();
da.Fill(ds);
DropDownList1.DataSource = ds.Tables[0];
DropDownList1.DataValueField = "academyName";
DropDownList1.DataTextField = "academyName";
DropDownList1.DataBind();//触发绑定事件
con.Close();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string strCon ="Data Source=.;" +
"Initial Catalog=studentManageSystem;" +
"Integrated Security=True;";
string strSQL = string.Format("select distinct academyprofession from academyCourse where academyName='{0}'", DropDownList1.SelectedValue.ToString().Trim());
SqlConnection con = new SqlConnection(strCon);
con.Open();
SqlDataAdapter da = new SqlDataAdapter(strSQL, con);
DataSet ds = new DataSet();
da.Fill(ds);
DropDownList2.DataSource = ds.Tables[0];
DropDownList2.DataValueField = "academyprofession";
DropDownList2.DataTextField = "academyprofession";
DropDownList2.DataBind();//触发绑定事件
con.Close();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
string strCon ="Data Source=.;" +
"Initial Catalog=studentManageSystem;" +
"Integrated Security=True;";
string strSQL = string.Format("select distinct classes from academyCourse where academyprofession='{0}'", DropDownList2.SelectedValue.ToString().Trim());
SqlConnection con = new SqlConnection(strCon);
con.Open();
SqlDataAdapter da = new SqlDataAdapter(strSQL, con);
DataSet ds = new DataSet();
da.Fill(ds);
DropDownList3.DataSource = ds.Tables[0];
DropDownList3.DataValueField = "classes";
DropDownList3.DataTextField = "classes";
DropDownList3.DataBind();//触发绑定事件
con.Close();