.NET實(shí)現(xiàn)Repeater控件+AspNetPager控件分頁(yè)
更新時(shí)間:2015年11月22日 11:20:01 投稿:hebedich
本文給大家分享的2個(gè)示例,演示AspNetPager最基本的功能,幫助您認(rèn)識(shí)AspNetPager分頁(yè)控件及了解它的工作原理。有需要的小伙伴可以參考下
當(dāng)然首先你要把bin文件放進(jìn)你的項(xiàng)目,并加到你的工具欄去
//頁(yè)頭需引用的 <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %> 控件部分(格式已經(jīng)設(shè)計(jì)好) <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="頁(yè)" TextBeforeInputBox="轉(zhuǎn)到第" CustomInfoHTML="共檢索到<strong>%RecordCount%</strong>條記錄 頁(yè)次:<strong>%CurrentPageIndex%/%PageCount%</strong> 每頁(yè)<strong>%PageSize%</strong>條" HorizontalAlign="Right" Width="100%" ShowInputBox="Always" OnPageChanged="AspNetPager1_PageChanged" PageSize="20" ShowBoxThreshold="1"> </webdiyer:AspNetPager>
后臺(tái)綁定的代碼
void databind()
{
int QYId = Convert.ToInt32(Request.Cookies["CompenyUser"].Value);//企業(yè)的Id
DataTable dt = bll.Viewlist(QYId);
this.AspNetPager1.RecordCount = dt.Rows.Count;//獲取數(shù)據(jù)的總數(shù)
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dt.DefaultView;//為控件綁定數(shù)據(jù)
pds.AllowPaging = true;//分頁(yè)啟用
pds.PageSize = AspNetPager1.PageSize;//獲取每頁(yè)顯示的數(shù)量
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
Repeater1.DataSource = pds;
Repeater1.DataBind();
}
分頁(yè),只需要把綁定放在AspNetPager1_PageChanged 事件里
再給大家一個(gè)實(shí)例
前臺(tái)頁(yè)面代碼
<%@ 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>通服產(chǎn)品</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>
<!--焦點(diǎn)圖-->
<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>
<!--焦點(diǎn)圖-->
</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">
【登陸】【注冊(cè)】
</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;">首頁(yè) |</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;">通服產(chǎn)品 |</a></div>
<div id="nav" align="center">
<a href="TF_Objects.aspx" target="_self" style="color:Black;">公司業(yè)績(jī) |</a></div>
<div id="nav" align="center">
<a href="TF_Servers.aspx" target="_self" style="color:Black;">服務(wù)中心 |</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;">關(guān)于我們 |</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>首頁(yè) > 通服產(chǎn)品</td>
<td> </td><td> </td>
<td align="right"><a href="Default.aspx">返回首頁(yè)</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">基建產(chǎn)品</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">無(wú)源器件</p>
<div class="menu_body">
<a href="TF_Product.aspx?id=5">天線</a> <a href="TF_Product.aspx?id=14">負(fù)載</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">防雷產(chǎn)品</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">電源產(chǎn)品</p>
<div class="menu_body">
<a href="TF_Product.aspx?id=12">開(kāi)關(guān)電源</a> <a href="TF_Product.aspx?id=23">USP電源</a>
<a href="TF_Product.aspx?id=61">遠(yuǎn)供電源</a> <a href="TF_Product.aspx?id=81">電源配套</a>
</div>
<p class="menu_head">IP通訊類產(chǎn)品</p>
<div class="menu_body">
<a href="TF_Product.aspx?id=27">IP網(wǎng)絡(luò)產(chǎn)品</a> <a href="TF_Product.aspx?id=29">IP無(wú)線產(chǎn)品</a>
<a href="TF_Product.aspx?id=30">IP安全產(chǎn)品</a> <a href="TF_Product.aspx?id=31">IP存儲(chǔ)及服務(wù)器</a>
<a href="TF_Product.aspx?id=32">IP多媒體產(chǎn)品</a> <a href="TF_Product.aspx?id=33">IP管理產(chǎn)品</a>
<a href="TF_Product.aspx?id=71">H3C產(chǎn)品</a> <a href="TF_Product.aspx?id=72">邁普產(chǎn)品</a>
<a href="TF_Product.aspx?id=73">迪普產(chǎn)品</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">轉(zhuǎn)換頭</a>
</div>
<p class="menu_head">服務(wù)類</p>
<div class="menu_body">
<a href="TF_Product.aspx?id=58">工程建設(shè)類</a> <a href="TF_Product.aspx?id=59">工程維護(hù)類</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">華為產(chǎn)品</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">標(biāo)準(zhǔn)件</a>
</div>
<p class="menu_head">其他</p>
<div class="menu_body">
<a href="TF_Product.aspx?id=66">郵費(fèi)差額</a> <a href="TF_Product.aspx?id=69">工程類服務(wù)費(fèi)用</a>
<a href="TF_Product.aspx?id=78">折扣</a> <a href="TF_Product.aspx?id=88">設(shè)備</a>
</div>
</div>
</td>
<td width="660" valign="top">
<div style="border-bottom:1px solid #DFEDFA; padding-left:2%; margin-left:2%;">
產(chǎn)品類別:<asp:DropDownList ID="ddlProductType" runat="server" DataTextField="pt_name" DataValueField="pt_id">
</asp:DropDownList>
關(guān)鍵字:<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">產(chǎn)品型號(hào):</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>產(chǎn)品編碼:</td>
<td><%#Eval("pr_bianma")%></td>
</tr>
<tr height="30px">
<td width="9px"> </td>
<td>產(chǎn)品描述:</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="首頁(yè)" LastPageText="尾頁(yè)" NextPageText="下一頁(yè)" PrevPageText="上一頁(yè)"
onpagechanged="AspNetPager1_PageChanged" PageSize="6" ShowMoreButtons="False" ShowPageIndexBox="Never">
</webdiyer:AspNetPager>
</div>
</div>
</td>
</tr>
</tbody>
</table>
<!--版權(quán)聲明-->
<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>
后臺(tái)代碼
Tb_productsHelper helper = new Tb_productsHelper();
IList<Tb_productsInfo> list = helper.GetAllListBySql(product_sql);
this.AspNetPager1.RecordCount = list.Count;//綁定總數(shù)量
this.AspNetPager1.AlwaysShow = true;
//先聲明一個(gè)分頁(yè)類對(duì)象
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();
您可能感興趣的文章:
- 在ASP.NET 2.0中操作數(shù)據(jù)之四十一:DataList和Repeater數(shù)據(jù)分頁(yè)
- asp.net Repeater分頁(yè)實(shí)例(PageDataSource的使用)
- asp.net中使用repeater和PageDataSource搭配實(shí)現(xiàn)分頁(yè)代碼
- asp.net中讓Repeater和GridView支持DataPager分頁(yè)
- asp.net下Repeater使用 AspNetPager分頁(yè)控件
- asp.net Repeater之非常好的數(shù)據(jù)分頁(yè)
- asp.net repeater手寫(xiě)分頁(yè)實(shí)例代碼
- ASP.NET程序中用Repeater實(shí)現(xiàn)分頁(yè)
- .NET中的repeater簡(jiǎn)介及分頁(yè)效果
相關(guān)文章
完美兼容ie和firefox的asp.net網(wǎng)站加入收藏和設(shè)置主頁(yè)
這篇文章主要介紹了完美兼容ie和firefox的asp.net網(wǎng)站加入收藏和設(shè)置主頁(yè),需要的朋友可以參考下2014-12-12
asp.net 相關(guān)文章實(shí)現(xiàn)方法
大家或許會(huì)覺(jué)得很驚訝:為什么靈感之源會(huì)討論SQL?或許應(yīng)該這樣說(shuō)吧:搞業(yè)務(wù)系統(tǒng),不跟SQL扯上關(guān)系似乎比較難。2009-05-05
ASP.NET MVC 從IHttp到頁(yè)面輸出的實(shí)例代碼
MVCHandler應(yīng)該算是MVC真正開(kāi)始的地方。MVCHandler實(shí)現(xiàn)了IHttpHandler接口,ProcessRequest便是方法入口2013-09-09
如何將asp.net core程序部署到Linux服務(wù)器
這篇文章主要介紹了將asp.net core程序部署到Linux服務(wù)器上的詳細(xì)過(guò)程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-09-09

