You must Sign In to post a response.
  • Category: ASP.NET

    ASP.NET2.0 Gridview sorting sample code

    Hi Viewers,

    I am new to ASP.NET(2.0) i want to write the code for gridview sorting.
    Please let me know the sample code.
  • #315403
    [Response removed by Admin. Read forum policies.]

  • #315407
    [Response removed by Admin. Read forum policies.]

  • #342405
    protected void gvSorting_Sorting(object sender, GridViewSortEventArgs e)
    {
    DataTable dtSortTable = gvSorting.DataSource as DataTable;

    if (dtSortTable != null)
    {
    DataView dvSortedView = new DataView(dtSortTable);
    dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection);

    gvSorting.DataSource = dvSortedView;
    gvSorting.DataBind();
    }
    }

    private string getSortDirectionString(SortDirection sortDireciton)
    {
    string newSortDirection = String.Empty;
    if(sortDirection== SortDirection.Ascending)
    {
    newSortDirection = "ASC";
    }
    else
    {
    newSortDirection = "DESC";
    }

    return newSortDirection
    }


This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.