Posted By

mpcircuitry on 07/01/10


Tagged

c Net aspnet


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Tyster


Sorting Gridview Control ASP.NET


 / Published in: C#
 

  1. protected void grdVw_FileList_Sorting(object sender, GridViewSortEventArgs e)
  2. {
  3.  
  4. GridSorting(e.SortExpression, grdVw_FileList);
  5.  
  6. }
  7.  
  8. private void GridSorting(string column, GridView grid)
  9. {
  10. // Session["column"] = ""; clear this after ever search/load
  11. string column_ASC = column + " ASC";
  12. string column_DESC = column + " DESC";
  13.  
  14. DataTable dt = (DataTable)Session["fileList"];
  15.  
  16. if (Session["column"].ToString().ToUpper() == column_ASC.ToUpper())
  17. {
  18. DataView dv = new DataView(dt, "", column_DESC, DataViewRowState.CurrentRows);
  19. grid.DataSource = dv;
  20. grid.DataBind();
  21. Session["column"] = column_DESC;
  22. }
  23. else
  24. {
  25. DataView dv = new DataView(dt, "", column_ASC, DataViewRowState.CurrentRows);
  26. grid.DataSource = dv;
  27. grid.DataBind();
  28. Session["column"] = column_ASC;
  29. }
  30.  
  31. }

Report this snippet  

You need to login to post a comment.