当前位置:Gxlcms > asp.net > .NET实现Repeater控件+AspNetPager控件分页

.NET实现Repeater控件+AspNetPager控件分页

时间:2021-07-01 10:21:17 帮助过:21人阅读

当然首先你要把bin文件放进你的项目,并加到你的工具栏去

  1. //页头需引用的
  2. <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
  3. 控件部分(格式已经设计好)
  4. <webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="True" FirstPageText="<font face='Webdings'>9</font>"
  5. LastPageText="<font face='Webdings'>:</font>" NextPageText="<font face='Webdings'>8</font>"
  6. PrevPageText="<font face='Webdings'>7</font>" ShowCustomInfoSection="Left" InputBoxStyle="width:19px"
  7. TextAfterInputBox="页" TextBeforeInputBox="转到第" CustomInfoHTML="共检索到<strong>%RecordCount%</strong>条记录 页次:<strong>%CurrentPageIndex%/%PageCount%</strong> 每页<strong>%PageSize%</strong>条"
  8. HorizontalAlign="Right" Width="100%" ShowInputBox="Always" OnPageChanged="AspNetPager1_PageChanged"
  9. PageSize="20" ShowBoxThreshold="1">
  10. </webdiyer:AspNetPager>

后台绑定的代码

  1. void databind()
  2. {
  3. int QYId = Convert.ToInt32(Request.Cookies["CompenyUser"].Value);//企业的Id
  4. DataTable dt = bll.Viewlist(QYId);
  5. this.AspNetPager1.RecordCount = dt.Rows.Count;//获取数据的总数
  6. PagedDataSource pds = new PagedDataSource();
  7. pds.DataSource = dt.DefaultView;//为控件绑定数据
  8. pds.AllowPaging = true;//分页启用
  9. pds.PageSize = AspNetPager1.PageSize;//获取每页显示的数量
  10. pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
  11. Repeater1.DataSource = pds;
  12. Repeater1.DataBind();
  13. }

分页,只需要把绑定放在AspNetPager1_PageChanged 事件里

再给大家一个实例

前台页面代码

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TF_Product.aspx.cs" Inherits="TF_Product" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix="webdiyer" %>
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head runat="server">
  6. <title>通服产品</title>
  7. <script src="jquery.js" type="text/javascript"></script>
  8. <script type="text/javascript">
  9. $(document).ready(function()
  10. {
  11. //slides the element with class "menu_body" when paragraph with class "menu_head" is clicked
  12. $("#firstpane p.menu_head").click(function()
  13. {
  14. $(this).css({backgroundImage:"url(down.png)"}).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
  15. $(this).siblings().css({backgroundImage:"url(left.png)"});
  16. });
  17. });
  18. </script>
  19. <style type="text/css">
  20. .menu_list { width: 229px; font-size:13px; }
  21. .menu_head { padding: 8px 60px; cursor: pointer; position: relative; margin:1px; height:16px; background: #DFEDFA url(left.png) center right no-repeat; }
  22. .menu_body { display:none;}
  23. .menu_body a { display:block; color:#006699; background-color:#EFEFEF; padding-left:60px; padding-top:8px; padding-bottom:3px; text-decoration:none; }
  24. .menu_body a:hover { color: #000000; text-decoration:underline; }
  25. </style>
  26. <meta name="keywords" content="通服科技">
  27. <meta name="description" content="江西通服科技有限公司">
  28. <link href="./Index_files/style.css" type="text/css" rel="stylesheet">
  29. <script src="js/AC_RunActiveContent.js" type="text/javascript"></script>
  30. <!--焦点图-->
  31. <style type="text/css">
  32. .anpager{background:#DFEDFA none repeat scroll 0 0;border:1px solid #CCCCCC;color:#FFFFFF;padding:4px 5px 4px 5px;}
  33. .container, .container *{margin:0; padding:0;}
  34. .container{width:886px; height:267px; overflow:hidden;position:relative;}
  35. .slider{position:absolute;}
  36. .slider li{ list-style:none;display:inline;}
  37. .slider img{ width:886px; height:267px; display:block;}
  38. .num{ position:absolute; right:5px; bottom:5px;}
  39. .num li{
  40. float: left;
  41. color: #FF7300;
  42. text-align: center;
  43. line-height: 16px;
  44. width: 16px;
  45. height: 16px;
  46. font-family: Arial;
  47. font-size: 12px;
  48. cursor: pointer;
  49. overflow: hidden;
  50. margin: 3px 1px;
  51. border: 1px solid #FF7300;
  52. background-color: #fff;
  53. }
  54. .num li.on{
  55. color: #fff;
  56. line-height: 21px;
  57. width: 21px;
  58. height: 21px;
  59. font-size: 16px;
  60. margin: 0 1px;
  61. border: 0;
  62. background-color: #FF7300;
  63. font-weight: bold;
  64. }
  65. </style>
  66. <!--焦点图-->
  67. </head>
  68. <body>
  69. <form runat="server">
  70. <!--头部-->
  71. <table width="878" height="114" border="0" align="center" cellpadding="0" cellspacing="2" bgcolor="#FFFFFF">
  72. <tbody>
  73. <tr>
  74. <td height="77">
  75. <table width="878px" border="0" cellpadding="0" cellspacing="0">
  76. <tbody>
  77. <tr><td width="73%" height="53" rowspan="2" align="left"><img src="./Index_files/LOGO_SY180-60.png" width="178" height="60" border="0"></td>
  78. <td width="27%" align="right" valign="top">
  79. 【登陆】【注册】
  80. </td>
  81. </tr>
  82. </tbody>
  83. </table>
  84. </td>
  85. </tr>
  86. <tr>
  87. <td width="878" align="center" style=" border-bottom:1px solid blue;" ><div style="width:100px; float:left;"></div>
  88. <div id="nav" align="center">
  89. <a href="Default.aspx" target="_self" style="color:Black;">首页 |</a></div>
  90. <div id="nav" align="center">
  91. <a href="TF_RecList.aspx" target="_self" style="color:Black;">新闻中心 |</a></div>
  92. <div id="nav" align="center">
  93. <a href="TF_Product.aspx" target="_self" style="color:Black;">通服产品 |</a></div>
  94. <div id="nav" align="center">
  95. <a href="TF_Objects.aspx" target="_self" style="color:Black;">公司业绩 |</a></div>
  96. <div id="nav" align="center">
  97. <a href="TF_Servers.aspx" target="_self" style="color:Black;">服务中心 |</a></div>
  98. <div id="nav" align="center">
  99. <a href="TF_Solution.aspx" target="_self" style="color:Black;">解决方案 |</a></div>
  100. <div id="nav" align="center">
  101. <a href="AboutUs.aspx" target="_self" style="color:Black;">关于我们 |</a></div>
  102. </td>
  103. </tr>
  104. <tr>
  105. <td align="center" width="878px">
  106. <div class="container" id="idTransformView">
  107. <ul class="slider" id="idSlider">
  108. <li><img src="images/01.jpg"/></li>
  109. </ul>
  110. </div>
  111. </td>
  112. </tr>
  113. </tbody>
  114. </table>
  115. <!--中间-->
  116. <table width="890" border="0" align="center" cellpadding="0" cellspacing="2" bgcolor="#FFFFFF">
  117. <tbody>
  118. <tr>
  119. <td>
  120. <div style="border:1px solid #DFEDFA; height:26px; padding-top:5px; padding-left:1%">
  121. <table width="100%">
  122. <tr>
  123. <td>首页 > 通服产品</td>
  124. <td> </td><td> </td>
  125. <td align="right"><a href="Default.aspx">返回首页</a></td>
  126. </tr>
  127. </table>
  128. </div>
  129. </td>
  130. </tr>
  131. </tbody>
  132. </table>
  133. <table width="890" border="0" align="center" cellpadding="0" cellspacing="2" bgcolor="#FFFFFF">
  134. <tbody>
  135. <tr>
  136. <td width="229" valign="top">
  137. <div>
  138. <img src="img/20140305165205.jpg" width="229px" />
  139. </div>
  140. <div id="firstpane" class="menu_list">
  141. <!--Code for menu starts here-->
  142. <p class="menu_head">基建产品</p>
  143. <div class="menu_body">
  144. <a href="TF_Product.aspx?id=45">普通基建</a><a href="TF_Product.aspx?id=46">美化基建</a>
  145. </div>
  146. <p class="menu_head">无源器件</p>
  147. <div class="menu_body">
  148. <a href="TF_Product.aspx?id=5">天线</a> <a href="TF_Product.aspx?id=14">负载</a>
  149. <a href="TF_Product.aspx?id=11">功分器</a> <a href="TF_Product.aspx?id=17">合路器</a>
  150. <a href="TF_Product.aspx?id=47">耦合器</a> <a href="TF_Product.aspx?id=56">双工器</a>
  151. <a href="TF_Product.aspx?id=70">AC安装配件</a> <a href="TF_Product.aspx?id=89">屏蔽器</a>
  152. </div>
  153. <p class="menu_head">防雷产品</p>
  154. <div class="menu_body">
  155. <a href="TF_Product.aspx?id=10">避雷器</a> <a href="TF_Product.aspx?id=57">防雷箱</a>
  156. </div>
  157. <p class="menu_head">电源产品</p>
  158. <div class="menu_body">
  159. <a href="TF_Product.aspx?id=12">开关电源</a> <a href="TF_Product.aspx?id=23">USP电源</a>
  160. <a href="TF_Product.aspx?id=61">远供电源</a> <a href="TF_Product.aspx?id=81">电源配套</a>
  161. </div>
  162. <p class="menu_head">IP通讯类产品</p>
  163. <div class="menu_body">
  164. <a href="TF_Product.aspx?id=27">IP网络产品</a> <a href="TF_Product.aspx?id=29">IP无线产品</a>
  165. <a href="TF_Product.aspx?id=30">IP安全产品</a> <a href="TF_Product.aspx?id=31">IP存储及服务器</a>
  166. <a href="TF_Product.aspx?id=32">IP多媒体产品</a> <a href="TF_Product.aspx?id=33">IP管理产品</a>
  167. <a href="TF_Product.aspx?id=71">H3C产品</a> <a href="TF_Product.aspx?id=72">迈普产品</a>
  168. <a href="TF_Product.aspx?id=73">迪普产品</a>
  169. </div>
  170. <p class="menu_head">工程辅材</p>
  171. <div class="menu_body">
  172. <a href="TF_Product.aspx?id=6">射频组件</a> <a href="TF_Product.aspx?id=7">电缆组件</a>
  173. <a href="TF_Product.aspx?id=8">光纤组件</a> <a href="TF_Product.aspx?id=9">五类缆组件</a>
  174. <a href="TF_Product.aspx?id=18">接地线</a> <a href="TF_Product.aspx?id=62">辅材包</a>
  175. <a href="TF_Product.aspx?id=82">套管</a> <a href="TF_Product.aspx?id=83">紧固件</a>
  176. </div>
  177. <p class="menu_head">连接器</p>
  178. <div class="menu_body">
  179. <a href="TF_Product.aspx?id=15">射频连接器</a> <a href="TF_Product.aspx?id=16">光纤连接器</a>
  180. <a href="TF_Product.aspx?id=63">转换头</a>
  181. </div>
  182. <p class="menu_head">服务类</p>
  183. <div class="menu_body">
  184. <a href="TF_Product.aspx?id=58">工程建设类</a> <a href="TF_Product.aspx?id=59">工程维护类</a>
  185. <a href="TF_Product.aspx?id=60">软件类</a>
  186. </div>
  187. <p class="menu_head">品牌分销</p>
  188. <div class="menu_body">
  189. <a href="TF_Product.aspx?id=87">华为产品</a>
  190. </div>
  191. <p class="menu_head">配件类</p>
  192. <div class="menu_body">
  193. <a href="TF_Product.aspx?id=67">配件类</a> <a href="TF_Product.aspx?id=86">标准件</a>
  194. </div>
  195. <p class="menu_head">其他</p>
  196. <div class="menu_body">
  197. <a href="TF_Product.aspx?id=66">邮费差额</a> <a href="TF_Product.aspx?id=69">工程类服务费用</a>
  198. <a href="TF_Product.aspx?id=78">折扣</a> <a href="TF_Product.aspx?id=88">设备</a>
  199. </div>
  200. </div>
  201. </td>
  202. <td width="660" valign="top">
  203. <div style="border-bottom:1px solid #DFEDFA; padding-left:2%; margin-left:2%;">
  204. 产品类别:<asp:DropDownList ID="ddlProductType" runat="server" DataTextField="pt_name" DataValueField="pt_id">
  205. </asp:DropDownList>
  206. 关键字:<asp:TextBox ID="txtGJZ" runat="server"></asp:TextBox>
  207. <asp:Button ID="btnSel" runat="server" Text="搜索" onclick="btnSel_Click" />
  208. </div>
  209. <div> </div>
  210. <div>
  211. <asp:Repeater ID="rp" runat="server">
  212. <ItemTemplate>
  213. <div style="margin-left:2%; border:1px solid #DFEDFA; padding:3px; margin-top:2px; margin-bottom:3px;">
  214. <table width="100%">
  215. <tr height="24px">
  216. <td rowspan="4" width="90px">
  217. <asp:Image ID="Image1" ImageUrl="~/Product_pic/NoPic.jpg" runat="server" Width="90px" Height="90px" />
  218. </td>
  219. <td width="9px"> </td>
  220. <td width="60px">产品型号:</td>
  221. <td><span style="float:left"><%#Eval("pr_guige")%></span><span style="float:right;"><a href="#">查看详情</a></span></td>
  222. </tr>
  223. <tr height="24px">
  224. <td width="9px"> </td>
  225. <td>产品编码:</td>
  226. <td><%#Eval("pr_bianma")%></td>
  227. </tr>
  228. <tr height="30px">
  229. <td width="9px"> </td>
  230. <td>产品描述:</td>
  231. <td><%#Eval("pr_ms")%></td>
  232. </tr>
  233. <tr><td height="8px"> </td></tr>
  234. </table>
  235. </div>
  236. </ItemTemplate>
  237. </asp:Repeater>
  238. <div style="height:22px; margin-left:2%;" align="right">
  239. <webdiyer:AspNetPager ID="AspNetPager1" CssClass="anpager" runat="server" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页"
  240. onpagechanged="AspNetPager1_PageChanged" PageSize="6" ShowMoreButtons="False" ShowPageIndexBox="Never">
  241. </webdiyer:AspNetPager>
  242. </div>
  243. </div>
  244. </td>
  245. </tr>
  246. </tbody>
  247. </table>
  248. <!--版权声明-->
  249. <table width="878" border="0" align="center">
  250. <tbody>
  251. <tr>
  252. <td>
  253. <img src="./Index_files/foot_02.gif" usemap="#foot" width="878">
  254. </td>
  255. </tr>
  256. </tbody>
  257. </table>
  258. </form>
  259. </body>
  260. </html>

后台代码

  1. Tb_productsHelper helper = new Tb_productsHelper();
  2. IList<Tb_productsInfo> list = helper.GetAllListBySql(product_sql);
  3. this.AspNetPager1.RecordCount = list.Count;//绑定总数量
  4. this.AspNetPager1.AlwaysShow = true;
  5. //先声明一个分页类对象
  6. PagedDataSource ps = new PagedDataSource();
  7. ps.AllowPaging = true;
  8. ps.PageSize = this.AspNetPager1.PageSize;
  9. ps.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex-1;
  10. ps.DataSource = list;
  11. this.rp.DataSource = ps;
  12. this.rp.DataBind();

人气教程排行