解析asp.net的分頁(yè)控件
一、說(shuō)明
AspNetPager.dll這個(gè)分頁(yè)控件主要用于asp.net webform網(wǎng)站,現(xiàn)將整理代碼如下
二、代碼
1、首先在測(cè)試頁(yè)面Default.aspx頁(yè)面添加引用
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
2、寫(xiě)一個(gè)Repeater列表控件用于顯示數(shù)據(jù)
<asp:Repeater ID="rptNews" runat="server"> <ItemTemplate> <li> <span><%# Eval("time") %></span> <a href="NewsShow.aspx?id=<%# Eval("id") %>"><%# Access.GetStringNum( Eval("name").ToString(),15) %></a> </li> </ItemTemplate> </asp:Repeater>
3、添加
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="True" CustomInfoStyle="FONT-SIZE: 12px" FirstPageText="首頁(yè)" HorizontalAlign="Center" inputboxstyle="width:19px" LastPageText="尾頁(yè)" meta:resourcekey="AspNetPager1" NextPageText="下一頁(yè)" PageSize="10" PrevPageText="上一頁(yè)" Style="font-size: 14px" Width="95%" CssClass="anpager" CurrentPageButtonClass="cpb" OnPageChanging="AspNetPager1_PageChanging" ShowBoxThreshold="10"> </webdiyer:AspNetPager>
PageSize屬性是用于設(shè)置每頁(yè)顯示的數(shù)量
4、后臺(tái)代碼綁定
//測(cè)試數(shù)據(jù)源<br>private void ShowNews() { String strSql = String.Format("select * from News order by time asc"); DataTable dtbl = Access.ExecuteDataTable(strSql, null); this.rptNews.DataSource = Access.GetPageDataSource(AspNetPager1, AspNetPager1.CurrentPageIndex - 1, dtbl); this.rptNews.DataBind(); }
Access是測(cè)試數(shù)據(jù)庫(kù)訪(fǎng)問(wèn)類(lèi),在最后的Demo中提供給大家
5、分頁(yè)控件點(diǎn)擊頁(yè)碼事件
//分頁(yè) protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e) { this.AspNetPager1.CurrentPageIndex = e.NewPageIndex; ShowNews(); }
最后奉上整頁(yè)代碼:
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %> <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>asp.net分頁(yè)控件</title> <link href="css/css.css" rel="stylesheet" type="text/css" /> <style type="text/css"> .aboutcontentnr{width:100%; height:auto; } </style> </head> <body> <form id="form1" runat="server"> <div> <ul class="news"> <asp:Repeater ID="rptNews" runat="server"> <ItemTemplate> <li><span> <%# Eval("time") %></span><a href="NewsShow.aspx?id=<%# Eval("id") %>"><%# Access.GetStringNum( Eval("name").ToString(),15) %></a></li> </ItemTemplate> </asp:Repeater> </ul> <div class="paginator"> <webdiyer:AspNetPager ID="AspNetPager1" runat="server" AlwaysShow="True" CustomInfoStyle="FONT-SIZE: 12px" FirstPageText="首頁(yè)" HorizontalAlign="Center" inputboxstyle="width:19px" LastPageText="尾頁(yè)" meta:resourcekey="AspNetPager1" NextPageText="下一頁(yè)" PageSize="10" PrevPageText="上一頁(yè)" Style="font-size: 14px" Width="95%" CssClass="anpager" CurrentPageButtonClass="cpb" OnPageChanging="AspNetPager1_PageChanging" ShowBoxThreshold="10"> </webdiyer:AspNetPager> </div> </div> </form> </body> </html>
Default.aspx.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ShowNews(); } } //測(cè)試數(shù)據(jù)源 private void ShowNews() { String strSql = String.Format("select * from News order by time asc"); DataTable dtbl = Access.ExecuteDataTable(strSql, null); this.rptNews.DataSource = Access.GetPageDataSource(AspNetPager1, AspNetPager1.CurrentPageIndex - 1, dtbl); this.rptNews.DataBind(); } //分頁(yè)點(diǎn)擊頁(yè)碼事件 protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e) { this.AspNetPager1.CurrentPageIndex = e.NewPageIndex; ShowNews(); } }
三、Demo
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流,同時(shí)也希望多多支持腳本之家!
- asp.net webform自定義分頁(yè)控件
- asp.net分頁(yè)控件使用詳解【附實(shí)例下載】
- asp.net自定義分頁(yè)控件示例
- 關(guān)于asp.net 自定義分頁(yè)控件
- asp.net中使用自定義控件的方式實(shí)現(xiàn)一個(gè)分頁(yè)控件的代碼
- 分享一個(gè)asp.net pager分頁(yè)控件
- asp.net分頁(yè)控件AspNetPager的樣式美化
- asp.net下Repeater使用 AspNetPager分頁(yè)控件
- AspNetAjaxPager,Asp.Net通用無(wú)刷新Ajax分頁(yè)控件,支持多樣式多數(shù)據(jù)綁定
- asp.net web頁(yè)面自定義分頁(yè)控件使用詳解
相關(guān)文章
asp.net用url重寫(xiě)URLReWriter實(shí)現(xiàn)任意二級(jí)域名
Asp.net 用url重寫(xiě)(URLReWriter)實(shí)現(xiàn)任意二級(jí)域名2008-10-10ASP.NET MVC中異常Exception攔截的深入理解
異常信息的處理在程序中非常重要, 在asp.net mvc中提供異常屬性攔截器進(jìn)行對(duì)異常信息的處理,下面這篇文章主要給大家介紹了關(guān)于ASP.NET MVC中異常Exception攔截的相關(guān)資料,需要的朋友可以參考下2018-07-07.NET微服務(wù)架構(gòu)CI/CD自動(dòng)構(gòu)建Jenkins+Gitee
這篇文章介紹了.NET使用微服務(wù)架構(gòu)CI/CD自動(dòng)構(gòu)建Jenkins+Gitee的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-01-01.NET6+Quartz實(shí)現(xiàn)定時(shí)任務(wù)的示例詳解
在實(shí)際工作中,經(jīng)常會(huì)有一些需要定時(shí)操作的業(yè)務(wù),如:定時(shí)發(fā)郵件,定時(shí)統(tǒng)計(jì)信息等,那么如何實(shí)現(xiàn)才能使得我們的項(xiàng)目整齊劃一呢?本文通過(guò)一些簡(jiǎn)單的小例子,簡(jiǎn)述在.Net6+Quartz實(shí)現(xiàn)定時(shí)任務(wù)的一些基本操作,如有不足之處,還請(qǐng)指正2023-03-03獲取客戶(hù)端IP地址c#/vb.net各自實(shí)現(xiàn)代碼
項(xiàng)目要求獲取客戶(hù)端的IP地址,分析并且用c#與vb各自實(shí)現(xiàn)了此要求,有需要的朋友可以了解下啊,希望本文對(duì)你們有所幫助2013-01-01擴(kuò)展ASP.NET MVC三層框架且使用StructureMap實(shí)現(xiàn)依賴(lài)注入1-Model層
本篇文章將向大家介紹如何添加Service和Repository層并且使用StructureMap把Service層注入到Controller,把Repository注入到Service層。2013-04-04ASP.NET中根據(jù)XML動(dòng)態(tài)創(chuàng)建使用WEB組件
ASP.NET中根據(jù)XML動(dòng)態(tài)創(chuàng)建使用WEB組件...2006-09-09