protected void FillGrid() { Organisation org = IsValidFormOrgID() ? OrganisationDB.GetByID(GetFormOrgID()) : null; if (!IsValidFormOrgID()) { lblHeading.Text = "Maintain Letters"; } else if (org == null) { lblHeading.Text = "Maintain Default Letters"; } else { lblHeading.Text = "Maintain Letters For "; lnkToEntity.Text = org.Name; lnkToEntity.NavigateUrl = "OrganisationDetailV2.aspx?type=view&id=" + org.OrganisationID; } DataTable dt = IsValidFormOrgID() ? LetterDB.GetDataTable_ByOrg(GetFormOrgID(), GetFormOrgID() == 0 ? Convert.ToInt32(Session["SiteID"]) : -1) : LetterDB.GetDataTable(Convert.ToInt32(Session["SiteID"])); Session["letter_data"] = dt; if (dt.Rows.Count > 0) { if (IsPostBack && Session["letter_sortexpression"] != null && Session["letter_sortexpression"].ToString().Length > 0) { DataView dataView = new DataView(dt); dataView.Sort = Session["letter_sortexpression"].ToString(); GrdLetter.DataSource = dataView; } else { GrdLetter.DataSource = dt; } try { GrdLetter.DataBind(); } catch (Exception ex) { HideTableAndSetErrorMessage("", ex.ToString()); } } else { dt.Rows.Add(dt.NewRow()); GrdLetter.DataSource = dt; GrdLetter.DataBind(); int TotalColumns = GrdLetter.Rows[0].Cells.Count; GrdLetter.Rows[0].Cells.Clear(); GrdLetter.Rows[0].Cells.Add(new TableCell()); GrdLetter.Rows[0].Cells[0].ColumnSpan = TotalColumns; GrdLetter.Rows[0].Cells[0].Text = "No Record Found"; } }