Posted By

mattvbiggs on 06/23/12


Tagged

sorting GridView


Versions (?)

Toggle Asc/Desc Sorting Gridview Columns


 / Published in: C#
 

When I first used this code, it was in the GridViewOnSorting event. This will sort the Sort Expression and Sort Direction in the ViewState. In the fillgrid() function I will pull these values from the ViewState to construct the sort.

  1. SortDirection sortdir = SortDirection.Ascending;
  2.  
  3. if (ViewState["SortDirection"] != null)
  4. {
  5. if ((string)ViewState["sortexp"] == e.SortExpression)
  6. {
  7. sortdir = (SortDirection)ViewState["SortDirection"] == SortDirection.Ascending ? SortDirection.Descending : SortDirection.Ascending;
  8. }
  9. }
  10.  
  11. string sortexp = e.SortExpression;
  12. ViewState["sortexp"] = sortexp;
  13. ViewState["SortDirection"] = sortdir;
  14. fill_grid();

Report this snippet  

You need to login to post a comment.