[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

原文地址:https://www.cnblogs.com/wolf-sun/p/3624085.html