Ramco Ramco

Ramco Ramco

  • 442
  • 3.4k
  • 528.7k

Data not getting Sorting

May 1 2023 6:45 AM

Hi

  It is going in SortGridview & SortExpression/Direction value also gets changed but it is not sorting the data.

private void SortGridView(string sortExpression, string direction)
{
    //  You can cache the DataTable for improving performance
    GetData();
    DataTable dt = grdPlanning.DataSource as DataTable;
    DataView dv = new DataView(dt);
    dv.Sort = sortExpression + direction;

    grdPlanning.DataSource = dv;
    grdPlanning.DataBind();

}
protected void grdPlanning_Sorting(object sender, GridViewSortEventArgs e)
{
    string sortExpression = e.SortExpression;

    if (GridViewSortDirection == SortDirection.Ascending)
    {
        GridViewSortDirection = SortDirection.Descending;
        SortGridView(sortExpression, DESCENDING);
    }
    else
    {
        GridViewSortDirection = SortDirection.Ascending;
        SortGridView(sortExpression, ASCENDING);
    }

}

private const string ASCENDING = " ASC";
private const string DESCENDING = " DESC";

public SortDirection GridViewSortDirection
{
    get
    {
        if (ViewState["sortDirection"] == null)
            ViewState["sortDirection"] = SortDirection.Ascending;

        return (SortDirection)ViewState["sortDirection"];
    }
    set
    {
        ViewState["sortDirection"] = value;
    }
}

 


Answers (1)