欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-12-18 20:46:16
当然首先你要把bin文件放进你的项目,并加到你的工具栏去 //页头需引用的 <%@ register assembly="aspnetpager" nam...

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

//页头需引用的
<%@ register assembly="aspnetpager" namespace="wuqi.webdiyer" tagprefix="webdiyer" %>

控件部分(格式已经设计好)
<webdiyer:aspnetpager id="aspnetpager1" runat="server" alwaysshow="true" firstpagetext="<font face='webdings'>9</font>"
 lastpagetext="<font face='webdings'>:</font>" nextpagetext="<font face='webdings'>8</font>"
 prevpagetext="<font face='webdings'>7</font>" showcustominfosection="left" inputboxstyle="width:19px"
 textafterinputbox="页" textbeforeinputbox="转到第" custominfohtml="共检索到<strong>%recordcount%</strong>条记录 页次:<strong>%currentpageindex%/%pagecount%</strong> 每页<strong>%pagesize%</strong>条"
 horizontalalign="right" width="100%" showinputbox="always" onpagechanged="aspnetpager1_pagechanged"
 pagesize="20" showboxthreshold="1">
</webdiyer:aspnetpager>

后台绑定的代码

void databind()
    {
      int qyid = convert.toint32(request.cookies["compenyuser"].value);//企业的id
      datatable dt = bll.viewlist(qyid);
      this.aspnetpager1.recordcount = dt.rows.count;//获取数据的总数

      pageddatasource pds = new pageddatasource();
      pds.datasource = dt.defaultview;//为控件绑定数据
      pds.allowpaging = true;//分页启用
      pds.pagesize = aspnetpager1.pagesize;//获取每页显示的数量
      pds.currentpageindex = aspnetpager1.currentpageindex - 1;

      repeater1.datasource = pds;
      repeater1.databind();
    }

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

再给大家一个实例

前台页面代码

<%@ page language="c#" autoeventwireup="true" codefile="tf_product.aspx.cs" inherits="tf_product" %>
 
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
 
 
<%@ register assembly="aspnetpager" namespace="wuqi.webdiyer" tagprefix="webdiyer" %>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>通服产品</title>
  <script src="jquery.js" type="text/javascript"></script>
  <script type="text/javascript">
  $(document).ready(function()
  {
    //slides the element with class "menu_body" when paragraph with class "menu_head" is clicked
    $("#firstpane p.menu_head").click(function()
    {
      $(this).css({backgroundimage:"url(down.png)"}).next("div.menu_body").slidetoggle(300).siblings("div.menu_body").slideup("slow");
      $(this).siblings().css({backgroundimage:"url(left.png)"});
    });
  });
  </script>
<style type="text/css">
.menu_list { width: 229px; font-size:13px; }
.menu_head { padding: 8px 60px; cursor: pointer; position: relative; margin:1px; height:16px; background: #dfedfa url(left.png) center right no-repeat; }
.menu_body { display:none;}
.menu_body a { display:block; color:#006699; background-color:#efefef; padding-left:60px; padding-top:8px; padding-bottom:3px; text-decoration:none; }
.menu_body a:hover { color: #000000; text-decoration:underline; }
</style>
<meta name="keywords" content="通服科技">
<meta name="description" content="江西通服科技有限公司">
<link href="./index_files/style.css" type="text/css" rel="stylesheet">
<script src="js/ac_runactivecontent.js" type="text/javascript"></script>
<!--焦点图-->
<style type="text/css">
.anpager{background:#dfedfa none repeat scroll 0 0;border:1px solid #cccccc;color:#ffffff;padding:4px 5px 4px 5px;}
.container, .container *{margin:0; padding:0;}
 
.container{width:886px; height:267px; overflow:hidden;position:relative;}
 
.slider{position:absolute;}
.slider li{ list-style:none;display:inline;}
.slider img{ width:886px; height:267px; display:block;}
 
.num{ position:absolute; right:5px; bottom:5px;}
.num li{
  float: left;
  color: #ff7300;
  text-align: center;
  line-height: 16px;
  width: 16px;
  height: 16px;
  font-family: arial;
  font-size: 12px;
  cursor: pointer;
  overflow: hidden;
  margin: 3px 1px;
  border: 1px solid #ff7300;
  background-color: #fff;
}
.num li.on{
  color: #fff;
  line-height: 21px;
  width: 21px;
  height: 21px;
  font-size: 16px;
  margin: 0 1px;
  border: 0;
  background-color: #ff7300;
  font-weight: bold;
}
</style>
<!--焦点图-->
</head>
<body>
<form runat="server">
<!--头部-->
<table width="878" height="114" border="0" align="center" cellpadding="0" cellspacing="2" bgcolor="#ffffff">
 <tbody>
 <tr>
  <td height="77">
   <table width="878px" border="0" cellpadding="0" cellspacing="0">
    <tbody>
    <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>
    <td width="27%" align="right" valign="top">
    【登陆】【注册】
    </td>
    </tr>
    </tbody>
   </table>
  </td>
 </tr>
 <tr>
  <td width="878" align="center" style=" border-bottom:1px solid blue;" ><div style="width:100px; float:left;"></div>
<div id="nav" align="center">
<a href="default.aspx" target="_self" style="color:black;">首页   |</a></div>
 
<div id="nav" align="center">
<a href="tf_reclist.aspx" target="_self" style="color:black;">新闻中心 |</a></div>
 
<div id="nav" align="center">
<a href="tf_product.aspx" target="_self" style="color:black;">通服产品 |</a></div>
 
<div id="nav" align="center">
<a href="tf_objects.aspx" target="_self" style="color:black;">公司业绩 |</a></div>
 
<div id="nav" align="center">
<a href="tf_servers.aspx" target="_self" style="color:black;">服务中心 |</a></div>
 
<div id="nav" align="center">
<a href="tf_solution.aspx" target="_self" style="color:black;">解决方案 |</a></div>
 
<div id="nav" align="center">
<a href="aboutus.aspx" target="_self" style="color:black;">关于我们 |</a></div>
</td>
 </tr>
 <tr>
  <td align="center" width="878px">
   <div class="container" id="idtransformview">
 <ul class="slider" id="idslider">
  <li><img src="images/01.jpg"/></li>
 </ul>
</div>
  </td>
 </tr>
</tbody>
</table>
<!--中间-->
<table width="890" border="0" align="center" cellpadding="0" cellspacing="2" bgcolor="#ffffff">
 <tbody>
 <tr>
 <td>
  <div style="border:1px solid #dfedfa; height:26px; padding-top:5px; padding-left:1%">
  <table width="100%">
  <tr>
  <td>首页 > 通服产品</td>
  <td> </td><td> </td>
  <td align="right"><a href="default.aspx">返回首页</a></td>
  </tr>
  </table>
  </div>
 </td>
 </tr>
 </tbody>
</table>
<table width="890" border="0" align="center" cellpadding="0" cellspacing="2" bgcolor="#ffffff">
 <tbody>
 <tr>
  <td width="229" valign="top">
  <div>
    <img src="img/20140305165205.jpg" width="229px" />
  </div>
   <div id="firstpane" class="menu_list">
    <!--code for menu starts here-->
    <p class="menu_head">基建产品</p>
    <div class="menu_body">
    <a href="tf_product.aspx?id=45">普通基建</a><a href="tf_product.aspx?id=46">美化基建</a>
    </div>
    <p class="menu_head">无源器件</p>
    <div class="menu_body">
     <a href="tf_product.aspx?id=5">天线</a> <a href="tf_product.aspx?id=14">负载</a>
     <a href="tf_product.aspx?id=11">功分器</a> <a href="tf_product.aspx?id=17">合路器</a>
     <a href="tf_product.aspx?id=47">耦合器</a> <a href="tf_product.aspx?id=56">双工器</a>
     <a href="tf_product.aspx?id=70">ac安装配件</a> <a href="tf_product.aspx?id=89">屏蔽器</a>
    </div>
    <p class="menu_head">防雷产品</p>
    <div class="menu_body">
     <a href="tf_product.aspx?id=10">避雷器</a> <a href="tf_product.aspx?id=57">防雷箱</a>
    </div>
    <p class="menu_head">电源产品</p>
    <div class="menu_body">
     <a href="tf_product.aspx?id=12">开关电源</a> <a href="tf_product.aspx?id=23">usp电源</a>
     <a href="tf_product.aspx?id=61">远供电源</a> <a href="tf_product.aspx?id=81">电源配套</a>
    </div>
    <p class="menu_head">ip通讯类产品</p>
    <div class="menu_body">
     <a href="tf_product.aspx?id=27">ip网络产品</a> <a href="tf_product.aspx?id=29">ip无线产品</a>
     <a href="tf_product.aspx?id=30">ip安全产品</a> <a href="tf_product.aspx?id=31">ip存储及服务器</a>
     <a href="tf_product.aspx?id=32">ip多媒体产品</a> <a href="tf_product.aspx?id=33">ip管理产品</a>
     <a href="tf_product.aspx?id=71">h3c产品</a> <a href="tf_product.aspx?id=72">迈普产品</a>
     <a href="tf_product.aspx?id=73">迪普产品</a>
    </div>
    <p class="menu_head">工程辅材</p>
    <div class="menu_body">
     <a href="tf_product.aspx?id=6">射频组件</a> <a href="tf_product.aspx?id=7">电缆组件</a>
     <a href="tf_product.aspx?id=8">光纤组件</a> <a href="tf_product.aspx?id=9">五类缆组件</a>
     <a href="tf_product.aspx?id=18">接地线</a> <a href="tf_product.aspx?id=62">辅材包</a>
     <a href="tf_product.aspx?id=82">套管</a> <a href="tf_product.aspx?id=83">紧固件</a>
    </div>
    <p class="menu_head">连接器</p>
    <div class="menu_body">
     <a href="tf_product.aspx?id=15">射频连接器</a> <a href="tf_product.aspx?id=16">光纤连接器</a>
     <a href="tf_product.aspx?id=63">转换头</a>
    </div>
    <p class="menu_head">服务类</p>
    <div class="menu_body">
     <a href="tf_product.aspx?id=58">工程建设类</a> <a href="tf_product.aspx?id=59">工程维护类</a>
     <a href="tf_product.aspx?id=60">软件类</a>
    </div>
    <p class="menu_head">品牌分销</p>
    <div class="menu_body">
     <a href="tf_product.aspx?id=87">华为产品</a>
    </div>
    <p class="menu_head">配件类</p>
    <div class="menu_body">
     <a href="tf_product.aspx?id=67">配件类</a> <a href="tf_product.aspx?id=86">标准件</a>
    </div>
    <p class="menu_head">其他</p>
    <div class="menu_body">
     <a href="tf_product.aspx?id=66">邮费差额</a> <a href="tf_product.aspx?id=69">工程类服务费用</a>
     <a href="tf_product.aspx?id=78">折扣</a> <a href="tf_product.aspx?id=88">设备</a>
    </div>
   </div>
  </td>
  <td width="660" valign="top">
  <div style="border-bottom:1px solid #dfedfa; padding-left:2%; margin-left:2%;">
  产品类别:<asp:dropdownlist id="ddlproducttype" runat="server" datatextfield="pt_name" datavaluefield="pt_id">
     </asp:dropdownlist>
    
  关键字:<asp:textbox id="txtgjz" runat="server"></asp:textbox>
    
     <asp:button id="btnsel" runat="server" text="搜索" onclick="btnsel_click" />
  </div>
  <div> </div>
  <div>
    <asp:repeater id="rp" runat="server">
    <itemtemplate>
     <div style="margin-left:2%; border:1px solid #dfedfa; padding:3px; margin-top:2px; margin-bottom:3px;">
     <table width="100%">
     <tr height="24px">
     <td rowspan="4" width="90px">
       <asp:image id="image1" imageurl="~/product_pic/nopic.jpg" runat="server" width="90px" height="90px" />
     </td>
     <td width="9px"> </td>
     <td width="60px">产品型号:</td>
     <td><span style="float:left"><%#eval("pr_guige")%></span><span style="float:right;"><a href="#">查看详情</a></span></td>
     </tr>
     <tr height="24px">
     <td width="9px"> </td>
     <td>产品编码:</td>
     <td><%#eval("pr_bianma")%></td>
     </tr>
     <tr height="30px">
     <td width="9px"> </td>
     <td>产品描述:</td>
     <td><%#eval("pr_ms")%></td>
     </tr>
     <tr><td height="8px"> </td></tr>
     </table>
     </div>
    </itemtemplate>
    </asp:repeater>
    <div style="height:22px; margin-left:2%;" align="right">
    <webdiyer:aspnetpager id="aspnetpager1" cssclass="anpager" runat="server" firstpagetext="首页" lastpagetext="尾页" nextpagetext="下一页" prevpagetext="上一页"
        onpagechanged="aspnetpager1_pagechanged" pagesize="6" showmorebuttons="false" showpageindexbox="never">
      </webdiyer:aspnetpager>
  </div>
  </div>
   
  </td>
 </tr>
</tbody>
</table>
<!--版权声明-->
<table width="878" border="0" align="center">
 <tbody>
 <tr>
 <td>
 <img src="./index_files/foot_02.gif" usemap="#foot" width="878">
 </td>
 </tr>
 </tbody>
</table>
</form>
</body>
</html>

后台代码

tb_productshelper helper = new tb_productshelper();
    ilist<tb_productsinfo> list = helper.getalllistbysql(product_sql);
    this.aspnetpager1.recordcount = list.count;//绑定总数量
    this.aspnetpager1.alwaysshow = true;
    //先声明一个分页类对象
    pageddatasource ps = new pageddatasource();
    ps.allowpaging = true;
    ps.pagesize = this.aspnetpager1.pagesize;
    ps.currentpageindex = this.aspnetpager1.currentpageindex-1;
    ps.datasource = list;
    this.rp.datasource = ps;
    this.rp.databind();

上一篇:

下一篇: