protected void GridView_Sorting(object sender, GridViewSortEventArgs e) { // dont allow sorting if in edit mode if (GrdTreatmentTemplateLetters.EditIndex >= 0) { return; } DataTable dataTable = Session["treatment_template_letters_data"] as DataTable; if (dataTable != null) { if (Session["treatment_template_letters_sortexpression"] == null) { Session["treatment_template_letters_sortexpression"] = ""; } DataView dataView = new DataView(dataTable); string[] sortData = Session["treatment_template_letters_sortexpression"].ToString().Trim().Split(' '); string newSortExpr = (e.SortExpression == sortData[0] && sortData[1] == "ASC") ? "DESC" : "ASC"; dataView.Sort = e.SortExpression + " " + newSortExpr; Session["treatment_template_letters_sortexpression"] = e.SortExpression + " " + newSortExpr; GrdTreatmentTemplateLetters.DataSource = dataView; GrdTreatmentTemplateLetters.DataBind(); } GrdTreatmentTemplateLetters.FooterRow.Visible = !hideFotter; }
protected void FillGrid() { DataTable dt = LetterTreatmentTemplateDB.GetDataTable(Convert.ToInt32(Session["SiteID"])); Session["treatment_template_letters_data"] = dt; if (dt.Rows.Count > 0) { if (IsPostBack && Session["treatment_template_letters_sortexpression"] != null && Session["treatment_template_letters_sortexpression"].ToString().Length > 0) { DataView dataView = new DataView(dt); dataView.Sort = Session["treatment_template_letters_sortexpression"].ToString(); GrdTreatmentTemplateLetters.DataSource = dataView; } else { GrdTreatmentTemplateLetters.DataSource = dt; } try { GrdTreatmentTemplateLetters.DataBind(); } catch (Exception ex) { HideTableAndSetErrorMessage("", ex.ToString()); } } else { dt.Rows.Add(dt.NewRow()); GrdTreatmentTemplateLetters.DataSource = dt; GrdTreatmentTemplateLetters.DataBind(); int TotalColumns = GrdTreatmentTemplateLetters.Rows[0].Cells.Count; GrdTreatmentTemplateLetters.Rows[0].Cells.Clear(); GrdTreatmentTemplateLetters.Rows[0].Cells.Add(new TableCell()); GrdTreatmentTemplateLetters.Rows[0].Cells[0].ColumnSpan = TotalColumns; GrdTreatmentTemplateLetters.Rows[0].Cells[0].Text = "No Record Found"; } if (GrdTreatmentTemplateLetters.FooterRow != null) { GrdTreatmentTemplateLetters.FooterRow.Visible = !hideFotter; } }