tags:

views:

9

answers:

1

Pls help me. I have created gridview with list daatsource. I want apply sorting event for gridview to sort all columns.

Here is my code:

protected void grduAdminSerservice_Sorting(object sender, GridViewSortEventArgs e) {

    DataTable tbl = grduAdminSerservice.DataSource as DataTable;

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

        grduAdminSerservice.DataSource = dv;
        grduAdminSerservice.DataBind();
    }

}

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

     return newSortDirection;
}

........

But table getting null value only . How can bind gridview source to table. Please help me