Posted By

krisdb on 07/25/08


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

rhainek


GridView sorting/Paging


 / Published in: C#
 

  1. OnSorting="gvName_Sorting"
  2. OnPageIndexChanging="gvName_PageIndexChanging"
  3.  
  4. protected void gvName_PageIndexChanging(object sender, GridViewPageEventArgs e)
  5. {
  6. gvName.PageIndex = e.NewPageIndex;
  7. BindEvents();
  8. }
  9.  
  10.  
  11. protected void gvName_Sorting(object sender, GridViewSortEventArgs e)
  12. {
  13. GridViewSortExpression = e.SortExpression;
  14. SetSortDirection();
  15. BindEvents();
  16. }
  17.  
  18. protected void BindEvents()
  19. {
  20. DataView dvName = new DataView();
  21.  
  22. dvName.Sort = GridViewSortExpression + " " + GridViewSortDirection;
  23.  
  24. dvName.DataSource = dvEvents;
  25. dvName.DataBind();
  26.  
  27. }
  28.  
  29. private string GridViewSortDirection
  30. {
  31. get { return ViewState["SortDirection"] as string ?? "DESC"; }
  32. set { ViewState["SortDirection"] = value; }
  33. }
  34.  
  35. private string GridViewSortExpression
  36. {
  37. get { return ViewState["SortExpression"] as string ?? "DEFAULT SORT COLUMN"; }
  38. set { ViewState["SortExpression"] = value; }
  39. }
  40.  
  41. private void SetSortDirection()
  42. {
  43. GridViewSortDirection = (GridViewSortDirection == "DESC") ? "ASC" : "DESC";
  44. }

Report this snippet  

You need to login to post a comment.