protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { List<Student> studentList = new List<Student>(); StudentManager studentManager = new StudentManager(); studentList = studentManager.getAllStudents(); chkStudent.DataSource = studentList; chkStudent.DataTextField = "FullName"; //chkStudent.DataTextFormatString = " {0}"; chkStudent.DataValueField = "StudentId"; //Start binding to the datasource chkStudent.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { List<Gender> genderList = new List<Gender>(); StudentManager studentManager = new StudentManager(); genderList = studentManager.getAllGender(); //using the List of Gender class instances as datasource ddlGender.DataSource = genderList; //tell the ddlGender to refer to the GenderName to display ddlGender.DataTextField = "GenderName"; //tell the ddlGender to refer to the GenderId property to //represent the displayed text. ddlGender.DataValueField = "GenderStatus"; //Start binding to the datasource ddlGender.DataBind(); }//using the if(Page.IsPostBack==false) condition //to ensure the binding logic will execute once. }