Guest User

Untitled

a guest
Jan 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using Test.Core;
  8.  
  9. namespace Test.Web
  10. {
  11. public partial class sand : System.Web.UI.Page
  12. {
  13. protected void Page_Load(object sender, EventArgs e)
  14. {
  15. if (!IsPostBack)
  16. {
  17. int pageIndex = 0;
  18. var model = new TestModel();
  19. dgSand.DataSource = model.FindAll(string.Empty, string.Empty, AdSource.All, true, hdnSortExpression.Value, dgSand.PageSize, pageIndex);
  20. dgSand.VirtualItemCount = model.FindAllCount(string.Empty, string.Empty, AdSource.All, true);
  21. dgSand.CurrentPageIndex = pageIndex;
  22. dgSand.DataBind();
  23. }
  24.  
  25. }
  26.  
  27. protected void dgSand_SortCommand(object source, DataGridSortCommandEventArgs e)
  28. {
  29. const string DESC = " desc";
  30. int descLength = DESC.Length;
  31. string newValue = e.SortExpression;
  32. string oldValue = hdnSortExpression.Value;
  33. if (oldValue == newValue)
  34. newValue += DESC;
  35. if (oldValue.EndsWith(DESC))
  36. newValue = oldValue.Remove(oldValue.Length - descLength, descLength);
  37. hdnSortExpression.Value = newValue;
  38.  
  39. int pageIndex = 0;
  40. var model = new TestModel();
  41. dgSand.DataSource = model.FindAll(string.Empty, string.Empty, AdSource.All, true, hdnSortExpression.Value, dgSand.PageSize, pageIndex);
  42. dgSand.VirtualItemCount = model.FindAllCount(string.Empty, string.Empty, AdSource.All, true);
  43. dgSand.CurrentPageIndex = pageIndex;
  44. dgSand.DataBind();
  45.  
  46. }
  47.  
  48. protected void dgSand_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
  49. {
  50. var model = new TestModel();
  51. var list = model.FindAll(string.Empty, string.Empty, AdSource.All, true, hdnSortExpression.Value,
  52. dgSand.PageSize, e.NewPageIndex * dgSand.PageSize);
  53. dgSand.DataSource = list;
  54. var count = model.FindAllCount(string.Empty, string.Empty, AdSource.All, true);
  55. dgSand.VirtualItemCount = count;
  56. dgSand.CurrentPageIndex = e.NewPageIndex;
  57. dgSand.DataBind();
  58. }
  59. }
  60. }
Add Comment
Please, Sign In to add comment