多级联动Dropdownlist(刷新版)
添加三个dropdownlist
<asp:DropDownList ID="a" runat="server" OnSelectedIndexChanged="a_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList> <asp:DropDownList ID="d" runat="server" OnSelectedIndexChanged="d_SelectedIndexChanged" AutoPostBack="true"></asp:DropDownList> <asp:DropDownList ID="m" runat="server"></asp:DropDownList>
后台代码
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.bindAcaData(); } } private void bindAcaData()//绑定学院 { AcadamyBLL ab = new AcadamyBLL(); this.a.DataSource = ab.SelectAll(); this.a.DataTextField = "academyName"; this.a.DataValueField = "id"; this.a.DataBind(); } private void bindDepData()//绑定学系 { DepartmentBLL db = new DepartmentBLL(); this.d.DataSource = db.SelectDepartmentByAcademy(this.a.SelectedValue); this.d.DataTextField = "departmentName"; this.d.DataValueField = "id"; this.d.DataBind(); } private void bindMajData()//绑定专业 { MajorBLL mb = new MajorBLL(); this.m.DataSource = mb.GetMajorByDepartment(this.d.SelectedValue); this.m.DataTextField = "majorName"; this.m.DataValueField = "id"; this.m.DataBind(); } protected void a_SelectedIndexChanged(object sender, EventArgs e) { this.bindDepData(); } protected void d_SelectedIndexChanged(object sender, EventArgs e) { this.bindMajData(); }