[Asp.net]AspNetPager分页组件

时间:2023-03-09 14:34:12
[Asp.net]AspNetPager分页组件

引言

在基于Asp.net的内网系统中,分页功能是最常用的,用的最多的组件就是AspNetPager。

AspNetPager

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

官网也提供了存储过程的生成工具,这里还是自己动手写吧,顺便在学习一下存储过程的语法:

 CREATE PROC Paged
@pageIndex INT,
@pageCount INT OUTPUT,
@pageSize INT
AS
DECLARE @count INT
SELECT @count= COUNT(*) FROM dbo.Student
SET @pageCount=CEILING(@count*1.0/@pageSize)
SELECT
*
FROM
(SELECT ROW_NUMBER() OVER(ORDER BY dbo.Student.stuId) AS tempId,* FROM dbo.Student) AS stu
WHERE tempId >=@pageSize*(@pageIndex-1)+1 AND tempId <=@pageIndex*@pageSize

在页面中引入组件:

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

分页样式一: 首页 上一页 下一页 尾页

  <webdiyer:AspNetPager ID="AspNetPager1" runat="server"
CustomInfoHTML="共%PageCount%页,当前为第%CurrentPageIndex%页,每页%PageSize%条,共%RecordCount%条"
FirstPageText="首页"
LastPageText="尾页"
NextPageText="下一页"
PageIndexBoxType="TextBox"
PrevPageText="上一页"
ShowCustomInfoSection="Left"
ShowPageIndex="False"
ShowPageIndexBox="Always"
SubmitButtonText="Go"
SubmitButtonClass="right_d_btn"
TextAfterPageIndexBox="页"
TextBeforePageIndexBox="转到"
OnPageChanging="AspNetPager1_PageChanging"
AlwaysShow="True"
PageSize="10"
ShowMoreButtons="false"
HorizontalAlign="Center">
</webdiyer:AspNetPager>

属性介绍:http://www.webdiyer.com/aspnetpagerdocs/

后台代码:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; namespace Wolfy.AspNetPagerDemo
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
InitGridView();
} protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
InitGridView();
}
private void InitGridView()
{
int count;
int pageCount;
gridStudent.DataSource = new BLL.StudentBLL().GetStudents(this.AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out pageCount, out count);
gridStudent.DataBind();
//赋值分页控件的总数
AspNetPager1.RecordCount = count;
}
}
}

效果:

[Asp.net]AspNetPager分页组件

效果二:页面导航 默认方式

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

效果:

[Asp.net]AspNetPager分页组件

总结

弄了两个较常用的样式,东西比较基础。纯粹娱乐。

代码下载:链接:http://pan.baidu.com/s/1o6I2bpw 密码:7ije