protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ClassBLL classBLL = new ClassBLL(); CourseBLL courBLL = new CourseBLL(); TeacherBLL teachBLL = new TeacherBLL(); //绑定页面查询条件的数据 DropDownList_class.DataSource = classBLL.getAll(); DropDownList_class.DataTextField = "name"; DropDownList_class.DataBind(); DropDownList_class.Items.Insert(0, "全部班级"); DropDownList_course.DataSource = courBLL.getAll(); DropDownList_course.DataTextField = "name"; DropDownList_course.DataBind(); DropDownList_course.Items.Insert(0, "全部课程"); DropDownList_teacher.DataSource = teachBLL.getTeachers(); DropDownList_teacher.DataTextField = "name"; DropDownList_teacher.DataBind(); DropDownList_teacher.Items.Insert(0, "全部教师"); bind(); } }
/// <summary> /// 绑定数据源 /// </summary> private void bind() { CourseBLL courBLL = new CourseBLL(); TeacherBLL teacherBLL = new TeacherBLL(); ClassBLL classBLL = new ClassBLL(); //绑定 "课程名称" 数据源 DropDownList_course.DataSource = courBLL.getAll(); DropDownList_course.DataTextField = "name"; DropDownList_course.DataValueField = "ID"; DropDownList_course.DataBind(); //绑定 "任课老师" 数据源 DropDownList_teacher.DataSource = teacherBLL.getTeachers(); DropDownList_teacher.DataTextField = "name"; DropDownList_teacher.DataValueField = "ID"; DropDownList_teacher.DataBind(); //绑定 "班级名称" 数据源 DropDownList_class.DataSource = classBLL.getAll(); DropDownList_class.DataTextField = "name"; DropDownList_class.DataValueField = "ID"; DropDownList_class.DataBind(); }