asp.net分頁控件使用詳解【附實(shí)例下載】
一、說明
AspNetPager.dll這個(gè)分頁控件主要用于asp.net webform網(wǎng)站,現(xiàn)將整理代碼如下
二、代碼
1、首先在測試頁面Default.aspx頁面添加引用
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
2、寫一個(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="首頁" HorizontalAlign="Center" inputboxstyle="width:19px" LastPageText="尾頁" meta:resourcekey="AspNetPager1" NextPageText="下一頁" PageSize="10" PrevPageText="上一頁" Style="font-size: 14px" Width="95%" CssClass="anpager" CurrentPageButtonClass="cpb" OnPageChanging="AspNetPager1_PageChanging" ShowBoxThreshold="10"> </webdiyer:AspNetPager>
PageSize屬性是用于設(shè)置每頁顯示的數(shù)量
4、后臺(tái)代碼綁定
Access是測試數(shù)據(jù)庫訪問類,在最后的Demo中提供給大家
5、分頁控件點(diǎn)擊頁碼事件
//分頁 protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e) { this.AspNetPager1.CurrentPageIndex = e.NewPageIndex; ShowNews(); }
最后奉上整頁代碼:
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分頁控件</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="首頁" HorizontalAlign="Center" inputboxstyle="width:19px" LastPageText="尾頁" meta:resourcekey="AspNetPager1" NextPageText="下一頁" PageSize="10" PrevPageText="上一頁" 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(); } } //測試數(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(); } //分頁點(diǎn)擊頁碼事件 protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e) { this.AspNetPager1.CurrentPageIndex = e.NewPageIndex; ShowNews(); } }
三、Demo
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!
相關(guān)文章
使用 .NET MAUI 開發(fā) ChatGPT 客戶端的流程
最近?chatgpt?很火,由于網(wǎng)頁版本限制了 ip,還得必須開代理,用起來比較麻煩,所以我嘗試用 maui 開發(fā)一個(gè)聊天小應(yīng)用,結(jié)合 chatgpt 的開放 api 來實(shí)現(xiàn),這篇文章主要介紹了使用 .NET MAUI 開發(fā) ChatGPT 客戶端,需要的朋友可以參考下2022-12-12asp.net創(chuàng)建位圖生成驗(yàn)證圖片類(驗(yàn)證碼類)
本文提供一個(gè)asp.net生成驗(yàn)證圖片的類,功能是顯示簡單的字符串,大家參考使用吧2014-01-01asp.net提取多層嵌套json數(shù)據(jù)的方法
這篇文章主要介紹了asp.net提取多層嵌套json數(shù)據(jù)的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了asp.net解析json格式數(shù)據(jù)的步驟與相關(guān)操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06簡單幾步 實(shí)現(xiàn)vs2010對(duì)html5的支持
微軟從來不會(huì)讓程序員用記事本寫代碼,如今html5馬上就要火起來vs2010怎么會(huì)不支持html5呢?月月bird我將vs2010支持html5的方法整理了一下。2016-05-05asp.net 圖標(biāo)提取以及圖標(biāo)轉(zhuǎn)換的實(shí)例代碼
asp.net 圖標(biāo)提取以及圖標(biāo)轉(zhuǎn)換的實(shí)例代碼,需要的朋友可以參考一下2013-06-06asp.net 實(shí)現(xiàn)自定義Hashtable (.net)
asp.net Hashtable自定義實(shí)現(xiàn)代碼,比較多,大家可以看下,測試。2009-06-06asp.net(c#)下各種進(jìn)制間的輕松轉(zhuǎn)換(2進(jìn)制、8進(jìn)制、10進(jìn)制、16進(jìn)制)
在.NET Framework中,System.Convert類中提供了較為全面的各種類型、數(shù)值之間的轉(zhuǎn)換功能。2010-10-10