//private string sql; protected void Page_Load(object sender, EventArgs e) { if ((Session["UserType"] == null) || (Session["UserType"].ToString() != "teacher")) { Response.Redirect("~/Login.aspx"); } //Response.Write("loaded from db"); Session["TeacherId"] = Session["UserId"]; Session["SearchQuery"] = "Select * from StudentInformation where TeacherId='" + Session["TeacherId"].ToString() + "'"; LoadStudentCards(); if (Session["SearchResult"] != null) { DataTable dt = (DataTable)Session["SearchResult"]; GridViewStudentSearch.DataSource = dt; GridViewStudentSearch.DataBind(); } else { LoadFromDatabaseForStudentSearch(); } if (!IsPostBack) { LoadTeacherCourseFromDatabase(); LoadSemesterFromDatabase(); //QueryBuilder(); //LoadStudentCards(); Session["SortingOrder"] = "ASC"; } }
protected void GridViewStudentSearch_Sorting(object sender, GridViewSortEventArgs e) { string SortingDerection = SetSortOrder(); if (Session["SearchResult"] != null) { //DataSet ds = (DataSet)Cache["DATASETSTUDENTSEARCH"]; DataTable dt = (DataTable)Session["SearchResult"]; //DataTable dt = (DataTable)GridViewStudentSearch.DataSource; //DataTable dt = ds.Tables["StudentInformation"]; dt.DefaultView.Sort = e.SortExpression + " " + SortingDerection; GridViewStudentSearch.DataSource = dt; GridViewStudentSearch.DataBind(); } else { DataSet ds = (DataSet)Cache["DATASETSTUDENTSEARCH"]; DataTable dt = (DataTable)ds.Tables["StudentInformation"]; dt.DefaultView.Sort = e.SortExpression + " " + SortingDerection; GridViewStudentSearch.DataSource = dt; GridViewStudentSearch.DataBind(); } }
protected void LoadFromDatabaseForStudentSearch() { string connStr = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; SqlConnection conn = new SqlConnection(connStr); string sql = Session["SearchQuery"].ToString(); //sql = "Select * from StudentInformation where TeacherId='"+Session["TeacherId"].ToString()+"'"; SqlDataAdapter AdapterStudentInformation = new SqlDataAdapter(sql, conn); SqlCommandBuilder builder = new SqlCommandBuilder(AdapterStudentInformation); DataSet ds = new DataSet(); AdapterStudentInformation.Fill(ds, "StudentInformation"); GridViewStudentSearch.DataSource = ds.Tables["StudentInformation"]; GridViewStudentSearch.DataBind(); Cache["DATASETSTUDENTSEARCH"] = ds; Cache["AdapterStudentInformation"] = AdapterStudentInformation; }
protected void ButtonSearch_Click(object sender, EventArgs e) { //QueryBuilder(); string sql = QueryBuilder(); //string sql = Session["SearchQuery"].ToString(); Response.Write(sql); //string sql = Session["SearchQuery"].ToString() + " and Grade > 3.75"; //sql += " and Grade > 3.75"; string connStr = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; SqlConnection conn = new SqlConnection(connStr); SqlDataAdapter AdapterStudentInformation = new SqlDataAdapter(sql, conn); SqlCommandBuilder builder = new SqlCommandBuilder(AdapterStudentInformation); DataSet ds = new DataSet(); AdapterStudentInformation.Fill(ds, "StudentInformation"); GridViewStudentSearch.DataSource = ds.Tables["StudentInformation"]; GridViewStudentSearch.DataBind(); Session["SearchResult"] = ds.Tables["StudentInformation"]; }