protected void GridView_Sorting(object sender, GridViewSortEventArgs e) { // dont allow sorting if in edit mode if (GrdPatientReferrer.EditIndex >= 0) { return; } DataTable dataTable = Session["patientreferrerhistory_data"] as DataTable; if (dataTable != null) { if (Session["patientreferrerhistory_sortexpression"] == null) { Session["patientreferrerhistory_sortexpression"] = ""; } DataView dataView = new DataView(dataTable); string[] sortData = Session["patientreferrerhistory_sortexpression"].ToString().Trim().Split(' '); string newSortExpr = (e.SortExpression == sortData[0] && sortData[1] == "ASC") ? "DESC" : "ASC"; dataView.Sort = e.SortExpression + " " + newSortExpr; Session["patientreferrerhistory_sortexpression"] = e.SortExpression + " " + newSortExpr; GrdPatientReferrer.DataSource = dataView; GrdPatientReferrer.DataBind(); } }
protected void FillGrid() { Patient patient = GetFormPatient(); if (patient == null) { SetErrorMessage("Invalid patient id"); return; } DataTable dt = PatientReferrerDB.GetDataTable_EPCReferrersOf(patient.PatientID); Session["patientreferrerhistory_data"] = dt; if (dt.Rows.Count > 0) { if (IsPostBack && Session["patientreferrerhistory_sortexpression"] != null && Session["patientreferrerhistory_sortexpression"].ToString().Length > 0) { DataView dataView = new DataView(dt); dataView.Sort = Session["patientreferrerhistory_sortexpression"].ToString(); GrdPatientReferrer.DataSource = dataView; } else { GrdPatientReferrer.DataSource = dt; } try { GrdPatientReferrer.DataBind(); GrdPatientReferrer.PagerSettings.FirstPageText = "1"; GrdPatientReferrer.PagerSettings.LastPageText = GrdPatientReferrer.PageCount.ToString(); GrdPatientReferrer.DataBind(); } catch (Exception ex) { SetErrorMessage(ex.ToString()); } } else { dt.Rows.Add(dt.NewRow()); GrdPatientReferrer.DataSource = dt; GrdPatientReferrer.DataBind(); int TotalColumns = GrdPatientReferrer.Rows[0].Cells.Count; GrdPatientReferrer.Rows[0].Cells.Clear(); GrdPatientReferrer.Rows[0].Cells.Add(new TableCell()); GrdPatientReferrer.Rows[0].Cells[0].ColumnSpan = TotalColumns; GrdPatientReferrer.Rows[0].Cells[0].Text = "No Record Found"; } }