private void LoadStudentDropDownList() { DataTable students = new DataTable(); using (SqlConnection sqlConnection = new SqlConnection(GetConnectionString())) { try { SqlDataAdapter dropDownListAdapter = new SqlDataAdapter("SELECT [StudentName], [StudentID] FROM [AppointmentTable] WHERE ([AdvisorID] = @AdvisorID)", sqlConnection); dropDownListAdapter.Fill(students); StudentsDropDownList.DataSource = students; StudentsDropDownList.DataTextField = "StudentName"; StudentsDropDownList.DataValueField = "StudentID"; StudentsDropDownList.DataBind(); } catch (SqlException exception) { throw new Exception(exception.Message); } } //Add first item in drop down list to be a "<Select Subject>" and an option to show all students again StudentsDropDownList.Items.Add(new ListItem("<Select Subject>", "-1")); StudentsDropDownList.Items.Add(new ListItem("All", "0")); }
protected void Page_Load(object sender, EventArgs e) { //Load relevant database tables userDB.AppointmentTables.Load(); userDB.StudentTables.Load(); //Clear any selections from the drop-down list of students so initial gridview shows all appointments LoadStudentDropDownList(); StudentsDropDownList.ClearSelection(); //DebugTextBox.Text = GetConnectionString(); //Initialize appointments table string initialSqlCommand = defaultSqlCommand; BindAppointments(initialSqlCommand, SqlParam.ADVISORID, Session["advisorID"].ToString()); //Load weekly calendar LoadWeeklyCalendar(); }