protected void Sort(string sortExpression, params string[] sortExpr)
    {
        DataTable dataTable = Session["data_email_history"] as DataTable;

        if (dataTable != null)
        {
            if (Session["sortExpression_email_history"] == null)
            {
                Session["sortExpression_email_history"] = "";
            }

            DataView dataView = new DataView(dataTable);
            string[] sortData = Session["sortExpression_email_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_email_history"] = sortExpression + " " + newSortExpr;

            GrdEmailHistory.DataSource = dataView;
            GrdEmailHistory.DataBind();
        }
    }
    protected void FillGrid()
    {
        DataTable dt = EmailHistoryDataDB.GetDataTable(2, false);

        Session["data_email_history"] = dt;

        if (dt.Rows.Count > 0)
        {
            if (IsPostBack && Session["sortExpression_email_history"] != null && Session["sortExpression_email_history"].ToString().Length > 0)
            {
                DataView dataView = new DataView(dt);
                dataView.Sort = Session["sortExpression_email_history"].ToString();
                GrdEmailHistory.DataSource = dataView;
            }
            else
            {
                GrdEmailHistory.DataSource = dt;
            }


            try
            {
                GrdEmailHistory.DataBind();
                GrdEmailHistory.PagerSettings.FirstPageText = "1";
                GrdEmailHistory.PagerSettings.LastPageText  = GrdEmailHistory.PageCount.ToString();
                GrdEmailHistory.DataBind();
            }
            catch (Exception ex)
            {
                SetErrorMessage(ex.ToString());
            }
        }
        else
        {
            dt.Rows.Add(dt.NewRow());
            GrdEmailHistory.DataSource = dt;
            GrdEmailHistory.DataBind();

            int TotalColumns = GrdEmailHistory.Rows[0].Cells.Count;
            GrdEmailHistory.Rows[0].Cells.Clear();
            GrdEmailHistory.Rows[0].Cells.Add(new TableCell());
            GrdEmailHistory.Rows[0].Cells[0].ColumnSpan = TotalColumns;
            GrdEmailHistory.Rows[0].Cells[0].Text       = "No Record Found";
        }
    }