/ Published in: C#
When I first used this code, it was in the GridView_OnSorting event. This will sort the Sort Expression and Sort Direction in the ViewState. In the fill_grid() function I will pull these values from the ViewState to construct the sort.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
SortDirection sortdir = SortDirection.Ascending; if (ViewState["SortDirection"] != null) { if ((string)ViewState["sortexp"] == e.SortExpression) { sortdir = (SortDirection)ViewState["SortDirection"] == SortDirection.Ascending ? SortDirection.Descending : SortDirection.Ascending; } } string sortexp = e.SortExpression; ViewState["sortexp"] = sortexp; ViewState["SortDirection"] = sortdir; fill_grid();