dropdownlist 二级联动

时间:2022-08-13 21:18:41
 protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
GradeBind();
} } //绑定年级
private void GradeBind()
{
Rubric.BLL.Grades myBll = new Rubric.BLL.Grades();
ddlGrade.DataSource = myBll.GetAllList();
ddlGrade.DataTextField = "Name";
ddlGrade.DataValueField = "GradeId";
ddlGrade.DataBind();
}
//ddlGrade的selectindexchanged事件
protected void ddlGrade_SelectedIndexChanged(object sender, EventArgs e)
{
string _gradeId = ddlGrade.SelectedValue.ToString();
string _str = "GradeId='" + _gradeId + "'";
Rubric.BLL.Courses myBll = new Rubric.BLL.Courses();
DataSet ds = myBll.GetList(_str);
ddlCourse.DataSource = ds;
ddlCourse.DataTextField = "Name";
ddlCourse.DataValueField = "CourseId";
ddlCourse.DataBind();
}