asp.net access数据库分页

access数据库分页程序

  1. <divclass="page"id="ctrlRecordPage">
  2. <asp:LabelID="Zpage"runat="server"Text="1"></asp:Label>页/
  3. <asp:LabelID="Zcount"runat="server"Text="0"></asp:Label>
  4. <asp:LinkButtonID="start_button"runat="server"onclick="start_button_Click">首页</asp:LinkButton>
  5. <asp:LinkButtonID="up_button"runat="server"onclick="up_button_Click">上一页</asp:LinkButton>
  6. <asp:LinkButtonID="down_button"runat="server"onclick="down_button_Click">下一页</asp:LinkButton>
  7. <asp:LinkButton ID="end_button" runat="server" onclick="end_button_Click">末页</asp:LinkButton>&nbsp;&nbsp;
  8. 每页<asp:TextBoxID="Pagesize"runat="server"Text="10"Width="30px"></asp:TextBox>
  9. 当前<asp:DropDownListID="Pageing"runat="server"AutoPostBack="True"
  10. onselectedindexchanged="Pageing_SelectedIndexChanged"></asp:DropDownList>
  11. </div>

  1. privatevoidPageing_databird(intvalue)
  2. {
  3. Pageing.Items.Clear();
  4. intzdatapage=Convert.ToInt32(Zpage.Text);
  5. if(zdatapage>0)
  6. {
  7. for(inti=1;i<=zdatapage;i++)
  8. {
  9. Pageing.Items.Add(i.ToString());
  10. }
  11. }
  12. else
  13. {
  14. Pageing.Items.Add("1");
  15. }
  16. if(Pageing.Items.FindByValue(value.ToString())!=null)Pageing.SelectedValue=value.ToString();
  17. if(zdatapage>1)
  18. {
  19. Pageing.Enabled=true;
  20. intdatapageing=Convert.ToInt32(Pageing.SelectedValue);
  21. if(datapageing>1)
  22. {
  23. start_button.Enabled=true;
  24. up_button.Enabled=true;
  25. }
  26. else
  27. {
  28. start_button.Enabled=false;
  29. up_button.Enabled=false;
  30. }
  31. if(datapageing<zdatapage)
  32. {
  33. down_button.Enabled=true;
  34. end_button.Enabled=true;
  35. }
  36. else
  37. {
  38. down_button.Enabled=false;
  39. end_button.Enabled=false;
  40. }
  41. }
  42. else
  43. {
  44. start_button.Enabled=false;
  45. up_button.Enabled=false;
  46. down_button.Enabled=false;
  47. end_button.Enabled=false;
  48. Pageing.Enabled=false;
  49. }
  50. }
  51. protectedvoidstart_button_Click(objectsender,EventArgse)
  52. {
  53. intdatapageing=1;
  54. if(Pageing.Items.FindByValue(datapageing.ToString())!=null)Pageing.SelectedValue=datapageing.ToString();
  55. DataBird();
  56. }
  57. protectedvoidup_button_Click(objectsender,EventArgse)
  58. {
  59. intdatapageing=Convert.ToInt32(Pageing.SelectedValue);
  60. if(datapageing>1)datapageing--;
  61. if(Pageing.Items.FindByValue(datapageing.ToString())!=null)Pageing.SelectedValue=datapageing.ToString();
  62. DataBird();
  63. }
  64. protectedvoiddown_button_Click(objectsender,EventArgse)
  65. {
  66. intdatapageing=Convert.ToInt32(Pageing.SelectedValue);
  67. intzdatapage=Convert.ToInt32(Zpage.Text);
  68. if(datapageing<zdatapage)datapageing++;
  69. if(Pageing.Items.FindByValue(datapageing.ToString())!=null)Pageing.SelectedValue=datapageing.ToString();
  70. DataBird();
  71. }
  72. protectedvoidend_button_Click(objectsender,EventArgse)
  73. {
  74. intzdatapage=Convert.ToInt32(Zpage.Text);
  75. if(Pageing.Items.FindByValue(zdatapage.ToString())!=null)Pageing.SelectedValue=zdatapage.ToString();
  76. DataBird();
  77. }
  78. protectedvoidPageing_SelectedIndexChanged(objectsender,EventArgse)
  79. {
  80. DataBird();
  81. }
  82. protectedvoidDataBird()
  83. {
  84. dc.Setsql="select*fromadlistorderbycreatetimedesc";
  85. DataTabledt=dc.GetDataTable(0);
  86. PagedDataSourcepds=newPagedDataSource();
  87. pds.DataSource=dt.DefaultView;
  88. pds.AllowPaging=true;
  89. intdatapagesize=10;
  90. if(Convert.ToInt32(Pagesize.Text)>0)datapagesize=Convert.ToInt32(Pagesize.Text);
  91. pds.PageSize=datapagesize;
  92. Zcount.Text=pds.DataSourceCount.ToString();
  93. Zpage.Text = pds.PageCount.ToString();
  94. intzpaging=1;
  95. if(Pageing.SelectedIndex>-1)zpaging=Convert.ToInt32(Pageing.SelectedValue);
  96. Pageing_databird(zpaging);
  97. pds.CurrentPageIndex=Convert.ToInt32(Pageing.SelectedValue)-1;
  98. listshow_Repeater.DataSource=pds;
  99. listshow_Repeater.DataBind();
  100. }

ok了!

你可能感兴趣的:(.net,asp.net,Access,UP,asp)