protected void Sort(string sortExpression, params string[] sortExpr) { DataTable dataTable = Session["data_sms_history"] as DataTable; if (dataTable != null) { if (Session["sortExpression_sms_history"] == null) { Session["sortExpression_sms_history"] = ""; } DataView dataView = new DataView(dataTable); string[] sortData = Session["sortExpression_sms_history"].ToString().Trim().Split(' '); string newSortExpr = (sortExpr.Length == 0) ? (sortExpression == sortData[0] && sortData[1] == "ASC") ? "DESC" : "ASC" : sortExpr[0]; dataView.Sort = sortExpression + " " + newSortExpr; Session["sortExpression_sms_history"] = sortExpression + " " + newSortExpr; GrdSMSHistory.DataSource = dataView; GrdSMSHistory.DataBind(); } }
protected void FillGrid() { DataTable dt = SMSHistoryDataDB.GetDataTable(1, false); Session["data_sms_history"] = dt; if (dt.Rows.Count > 0) { if (IsPostBack && Session["sortExpression_sms_history"] != null && Session["sortExpression_sms_history"].ToString().Length > 0) { DataView dataView = new DataView(dt); dataView.Sort = Session["sortExpression_sms_history"].ToString(); GrdSMSHistory.DataSource = dataView; } else { GrdSMSHistory.DataSource = dt; } try { GrdSMSHistory.DataBind(); GrdSMSHistory.PagerSettings.FirstPageText = "1"; GrdSMSHistory.PagerSettings.LastPageText = GrdSMSHistory.PageCount.ToString(); GrdSMSHistory.DataBind(); } catch (Exception ex) { SetErrorMessage(ex.ToString()); } } else { dt.Rows.Add(dt.NewRow()); GrdSMSHistory.DataSource = dt; GrdSMSHistory.DataBind(); int TotalColumns = GrdSMSHistory.Rows[0].Cells.Count; GrdSMSHistory.Rows[0].Cells.Clear(); GrdSMSHistory.Rows[0].Cells.Add(new TableCell()); GrdSMSHistory.Rows[0].Cells[0].ColumnSpan = TotalColumns; GrdSMSHistory.Rows[0].Cells[0].Text = "No Record Found"; } }