[Asp.net]AspNetPager分頁組件


引言

在基於Asp.net的內網系統中,分頁功能是最常用的,用的最多的組件就是AspNetPager。

AspNetPager

官網:http://www.webdiyer.com/aspnetpager/

官網也提供了存儲過程的生成工具,這里還是自己動手寫吧,順便在學習一下存儲過程的語法:

 1 CREATE PROC Paged
 2 @pageIndex INT,
 3 @pageCount INT OUTPUT,
 4 @pageSize INT 
 5 AS
 6 DECLARE @count INT
 7 SELECT @count= COUNT(*) FROM dbo.Student
 8 SET @pageCount=CEILING(@count*1.0/@pageSize)
 9 SELECT 
10 * 
11 FROM 
12 (SELECT ROW_NUMBER() OVER(ORDER BY dbo.Student.stuId) AS tempId,* FROM dbo.Student) AS stu
13 WHERE tempId >=@pageSize*(@pageIndex-1)+1 AND tempId <=@pageIndex*@pageSize

在頁面中引入組件:

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

分頁樣式一: 首頁 上一頁 下一頁 尾頁

 1  <webdiyer:AspNetPager ID="AspNetPager1" runat="server"
 2                 CustomInfoHTML="共%PageCount%頁,當前為第%CurrentPageIndex%頁,每頁%PageSize%條,共%RecordCount%條"
 3                 FirstPageText="首頁" 
 4                 LastPageText="尾頁" 
 5                 NextPageText="下一頁"
 6                 PageIndexBoxType="TextBox"
 7                 PrevPageText="上一頁" 
 8                 ShowCustomInfoSection="Left"
 9                 ShowPageIndex="False" 
10                 ShowPageIndexBox="Always" 
11                 SubmitButtonText="Go" 
12                 SubmitButtonClass="right_d_btn"
13                 TextAfterPageIndexBox="頁" 
14                 TextBeforePageIndexBox="轉到"
15                 OnPageChanging="AspNetPager1_PageChanging" 
16                 AlwaysShow="True" 
17                 PageSize="10" 
18                 ShowMoreButtons="false" 
19                 HorizontalAlign="Center">
20             </webdiyer:AspNetPager>

屬性介紹:http://www.webdiyer.com/aspnetpagerdocs/

后台代碼:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.UI;
 6 using System.Web.UI.WebControls;
 7 
 8 namespace Wolfy.AspNetPagerDemo
 9 {
10     public partial class Default : System.Web.UI.Page
11     {
12         protected void Page_Load(object sender, EventArgs e)
13         {
14             InitGridView();
15         }
16 
17         protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
18         {
19             this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
20             InitGridView();
21         }
22         private void InitGridView()
23         {
24             int count;
25             int pageCount;
26             gridStudent.DataSource = new BLL.StudentBLL().GetStudents(this.AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out pageCount, out count);
27             gridStudent.DataBind();
28             //賦值分頁控件的總數
29             AspNetPager1.RecordCount = count;
30         }
31     }
32 }
View Code

效果:

效果二:頁面導航 默認方式

 1  <form id="form1" runat="server">
 2          <asp:gridview runat="server" ID="gridStudent"></asp:gridview>
 3     <div>
 4             <%-- 分頁樣式二 默認方式 1 2 3 4 5 6 7...--%>
 5            
 6             <webdiyer:AspNetPager ID="AspNetPager1" runat="server" PageSize="5"
 7                 OnPageChanging="AspNetPager1_PageChanging">
 8             </webdiyer:AspNetPager>
 9         </div>
10     </form>

效果:

總結

弄了兩個較常用的樣式,東西比較基礎。純粹娛樂。

代碼下載:鏈接:http://pan.baidu.com/s/1o6I2bpw 密碼:7ije


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM