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