.NET实现Repeater控件+AspNetPager控件分页
当然首先你要把bin文件放进你的项目,并加到你的工具栏去
//页头需引用的 <%@RegisterAssembly="AspNetPager"Namespace="Wuqi.Webdiyer"TagPrefix="webdiyer"%> 控件部分(格式已经设计好) <webdiyer:AspNetPagerID="AspNetPager1"runat="server"AlwaysShow="True"FirstPageText="<fontface='Webdings'>9</font>" LastPageText="<fontface='Webdings'>:</font>"NextPageText="<fontface='Webdings'>8</font>" PrevPageText="<fontface='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>
后台绑定的代码
voiddatabind()
{
intQYId=Convert.ToInt32(Request.Cookies["CompenyUser"].Value);//企业的Id
DataTabledt=bll.Viewlist(QYId);
this.AspNetPager1.RecordCount=dt.Rows.Count;//获取数据的总数
PagedDataSourcepds=newPagedDataSource();
pds.DataSource=dt.DefaultView;//为控件绑定数据
pds.AllowPaging=true;//分页启用
pds.PageSize=AspNetPager1.PageSize;//获取每页显示的数量
pds.CurrentPageIndex=AspNetPager1.CurrentPageIndex-1;
Repeater1.DataSource=pds;
Repeater1.DataBind();
}
分页,只需要把绑定放在AspNetPager1_PageChanged事件里
再给大家一个实例
前台页面代码
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="TF_Product.aspx.cs"Inherits="TF_Product"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@Registerassembly="AspNetPager"namespace="Wuqi.Webdiyer"tagprefix="webdiyer"%>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>通服产品</title>
<scriptsrc="jquery.js"type="text/javascript"></script>
<scripttype="text/javascript">
$(document).ready(function()
{
//slidestheelementwithclass"menu_body"whenparagraphwithclass"menu_head"isclicked
$("#firstpanep.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>
<styletype="text/css">
.menu_list{width:229px;font-size:13px;}
.menu_head{padding:8px60px;cursor:pointer;position:relative;margin:1px;height:16px;background:#DFEDFAurl(left.png)centerrightno-repeat;}
.menu_body{display:none;}
.menu_bodya{display:block;color:#006699;background-color:#EFEFEF;padding-left:60px;padding-top:8px;padding-bottom:3px;text-decoration:none;}
.menu_bodya:hover{color:#000000;text-decoration:underline;}
</style>
<metaname="keywords"content="通服科技">
<metaname="description"content="江西通服科技有限公司">
<linkhref="./Index_files/style.css"type="text/css"rel="stylesheet">
<scriptsrc="js/AC_RunActiveContent.js"type="text/javascript"></script>
<!--焦点图-->
<styletype="text/css">
.anpager{background:#DFEDFAnonerepeatscroll00;border:1pxsolid#CCCCCC;color:#FFFFFF;padding:4px5px4px5px;}
.container,.container*{margin:0;padding:0;}
.container{width:886px;height:267px;overflow:hidden;position:relative;}
.slider{position:absolute;}
.sliderli{list-style:none;display:inline;}
.sliderimg{width:886px;height:267px;display:block;}
.num{position:absolute;right:5px;bottom:5px;}
.numli{
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:3px1px;
border:1pxsolid#FF7300;
background-color:#fff;
}
.numli.on{
color:#fff;
line-height:21px;
width:21px;
height:21px;
font-size:16px;
margin:01px;
border:0;
background-color:#FF7300;
font-weight:bold;
}
</style>
<!--焦点图-->
</head>
<body>
<formrunat="server">
<!--头部-->
<tablewidth="878"height="114"border="0"align="center"cellpadding="0"cellspacing="2"bgcolor="#FFFFFF">
<tbody>
<tr>
<tdheight="77">
<tablewidth="878px"border="0"cellpadding="0"cellspacing="0">
<tbody>
<tr><tdwidth="73%"height="53"rowspan="2"align="left"><imgsrc="./Index_files/LOGO_SY180-60.png"width="178"height="60"border="0"></td>
<tdwidth="27%"align="right"valign="top">
【登陆】【注册】
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<tdwidth="878"align="center"style="border-bottom:1pxsolidblue;"><divstyle="width:100px;float:left;"></div>
<divid="nav"align="center">
<ahref="Default.aspx"target="_self"style="color:Black;">首页|</a></div>
<divid="nav"align="center">
<ahref="TF_RecList.aspx"target="_self"style="color:Black;">新闻中心|</a></div>
<divid="nav"align="center">
<ahref="TF_Product.aspx"target="_self"style="color:Black;">通服产品|</a></div>
<divid="nav"align="center">
<ahref="TF_Objects.aspx"target="_self"style="color:Black;">公司业绩|</a></div>
<divid="nav"align="center">
<ahref="TF_Servers.aspx"target="_self"style="color:Black;">服务中心|</a></div>
<divid="nav"align="center">
<ahref="TF_Solution.aspx"target="_self"style="color:Black;">解决方案|</a></div>
<divid="nav"align="center">
<ahref="AboutUs.aspx"target="_self"style="color:Black;">关于我们|</a></div>
</td>
</tr>
<tr>
<tdalign="center"width="878px">
<divclass="container"id="idTransformView">
<ulclass="slider"id="idSlider">
<li><imgsrc="images/01.jpg"/></li>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
<!--中间-->
<tablewidth="890"border="0"align="center"cellpadding="0"cellspacing="2"bgcolor="#FFFFFF">
<tbody>
<tr>
<td>
<divstyle="border:1pxsolid#DFEDFA;height:26px;padding-top:5px;padding-left:1%">
<tablewidth="100%">
<tr>
<td>首页>通服产品</td>
<td></td><td></td>
<tdalign="right"><ahref="Default.aspx">返回首页</a></td>
</tr>
</table>
</div>
</td>
</tr>
</tbody>
</table>
<tablewidth="890"border="0"align="center"cellpadding="0"cellspacing="2"bgcolor="#FFFFFF">
<tbody>
<tr>
<tdwidth="229"valign="top">
<div>
<imgsrc="img/20140305165205.jpg"width="229px"/>
</div>
<divid="firstpane"class="menu_list">
<!--Codeformenustartshere-->
<pclass="menu_head">基建产品</p>
<divclass="menu_body">
<ahref="TF_Product.aspx?id=45">普通基建</a><ahref="TF_Product.aspx?id=46">美化基建</a>
</div>
<pclass="menu_head">无源器件</p>
<divclass="menu_body">
<ahref="TF_Product.aspx?id=5">天线</a><ahref="TF_Product.aspx?id=14">负载</a>
<ahref="TF_Product.aspx?id=11">功分器</a><ahref="TF_Product.aspx?id=17">合路器</a>
<ahref="TF_Product.aspx?id=47">耦合器</a><ahref="TF_Product.aspx?id=56">双工器</a>
<ahref="TF_Product.aspx?id=70">AC安装配件</a><ahref="TF_Product.aspx?id=89">屏蔽器</a>
</div>
<pclass="menu_head">防雷产品</p>
<divclass="menu_body">
<ahref="TF_Product.aspx?id=10">避雷器</a><ahref="TF_Product.aspx?id=57">防雷箱</a>
</div>
<pclass="menu_head">电源产品</p>
<divclass="menu_body">
<ahref="TF_Product.aspx?id=12">开关电源</a><ahref="TF_Product.aspx?id=23">USP电源</a>
<ahref="TF_Product.aspx?id=61">远供电源</a><ahref="TF_Product.aspx?id=81">电源配套</a>
</div>
<pclass="menu_head">IP通讯类产品</p>
<divclass="menu_body">
<ahref="TF_Product.aspx?id=27">IP网络产品</a><ahref="TF_Product.aspx?id=29">IP无线产品</a>
<ahref="TF_Product.aspx?id=30">IP安全产品</a><ahref="TF_Product.aspx?id=31">IP存储及服务器</a>
<ahref="TF_Product.aspx?id=32">IP多媒体产品</a><ahref="TF_Product.aspx?id=33">IP管理产品</a>
<ahref="TF_Product.aspx?id=71">H3C产品</a><ahref="TF_Product.aspx?id=72">迈普产品</a>
<ahref="TF_Product.aspx?id=73">迪普产品</a>
</div>
<pclass="menu_head">工程辅材</p>
<divclass="menu_body">
<ahref="TF_Product.aspx?id=6">射频组件</a><ahref="TF_Product.aspx?id=7">电缆组件</a>
<ahref="TF_Product.aspx?id=8">光纤组件</a><ahref="TF_Product.aspx?id=9">五类缆组件</a>
<ahref="TF_Product.aspx?id=18">接地线</a><ahref="TF_Product.aspx?id=62">辅材包</a>
<ahref="TF_Product.aspx?id=82">套管</a><ahref="TF_Product.aspx?id=83">紧固件</a>
</div>
<pclass="menu_head">连接器</p>
<divclass="menu_body">
<ahref="TF_Product.aspx?id=15">射频连接器</a><ahref="TF_Product.aspx?id=16">光纤连接器</a>
<ahref="TF_Product.aspx?id=63">转换头</a>
</div>
<pclass="menu_head">服务类</p>
<divclass="menu_body">
<ahref="TF_Product.aspx?id=58">工程建设类</a><ahref="TF_Product.aspx?id=59">工程维护类</a>
<ahref="TF_Product.aspx?id=60">软件类</a>
</div>
<pclass="menu_head">品牌分销</p>
<divclass="menu_body">
<ahref="TF_Product.aspx?id=87">华为产品</a>
</div>
<pclass="menu_head">配件类</p>
<divclass="menu_body">
<ahref="TF_Product.aspx?id=67">配件类</a><ahref="TF_Product.aspx?id=86">标准件</a>
</div>
<pclass="menu_head">其他</p>
<divclass="menu_body">
<ahref="TF_Product.aspx?id=66">邮费差额</a><ahref="TF_Product.aspx?id=69">工程类服务费用</a>
<ahref="TF_Product.aspx?id=78">折扣</a><ahref="TF_Product.aspx?id=88">设备</a>
</div>
</div>
</td>
<tdwidth="660"valign="top">
<divstyle="border-bottom:1pxsolid#DFEDFA;padding-left:2%;margin-left:2%;">
产品类别:<asp:DropDownListID="ddlProductType"runat="server"DataTextField="pt_name"DataValueField="pt_id">
</asp:DropDownList>
关键字:<asp:TextBoxID="txtGJZ"runat="server"></asp:TextBox>
<asp:ButtonID="btnSel"runat="server"Text="搜索"onclick="btnSel_Click"/>
</div>
<div></div>
<div>
<asp:RepeaterID="rp"runat="server">
<ItemTemplate>
<divstyle="margin-left:2%;border:1pxsolid#DFEDFA;padding:3px;margin-top:2px;margin-bottom:3px;">
<tablewidth="100%">
<trheight="24px">
<tdrowspan="4"width="90px">
<asp:ImageID="Image1"ImageUrl="~/Product_pic/NoPic.jpg"runat="server"Width="90px"Height="90px"/>
</td>
<tdwidth="9px"></td>
<tdwidth="60px">产品型号:</td>
<td><spanstyle="float:left"><%#Eval("pr_guige")%></span><spanstyle="float:right;"><ahref="#">查看详情</a></span></td>
</tr>
<trheight="24px">
<tdwidth="9px"></td>
<td>产品编码:</td>
<td><%#Eval("pr_bianma")%></td>
</tr>
<trheight="30px">
<tdwidth="9px"></td>
<td>产品描述:</td>
<td><%#Eval("pr_ms")%></td>
</tr>
<tr><tdheight="8px"></td></tr>
</table>
</div>
</ItemTemplate>
</asp:Repeater>
<divstyle="height:22px;margin-left:2%;"align="right">
<webdiyer:AspNetPagerID="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>
<!--版权声明-->
<tablewidth="878"border="0"align="center">
<tbody>
<tr>
<td>
<imgsrc="./Index_files/foot_02.gif"usemap="#foot"width="878">
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
后台代码
Tb_productsHelperhelper=newTb_productsHelper(); IList<Tb_productsInfo>list=helper.GetAllListBySql(product_sql); this.AspNetPager1.RecordCount=list.Count;//绑定总数量 this.AspNetPager1.AlwaysShow=true; //先声明一个分页类对象 PagedDataSourceps=newPagedDataSource(); ps.AllowPaging=true; ps.PageSize=this.AspNetPager1.PageSize; ps.CurrentPageIndex=this.AspNetPager1.CurrentPageIndex-1; ps.DataSource=list; this.rp.DataSource=ps; this.rp.DataBind();