We Recommend

Accelerated C# 2008 Accelerated C# 2008
This book is both a rapid tutorial and a permanent reference. You’ll quickly master C# syntax while learning how the CLR simplifies many programming tasks. You’ll also learn best practices that ensure your code will be efficient, reusable, and robust. Why spend months or years discovering the best ways to design and code C# when this book will show you how to do things the right way, right from the start?


Posted By

krisdb on 07/25/08


Tagged


Versions (?)


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.