引言
在基於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;
}
}
}
效果:
![]()
效果二:頁面導航 默認方式
<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>
效果:
![]()
弄了兩個較常用的樣式,東西比較基礎。純粹娛樂。
代碼下載:鏈接:http://pan.baidu.com/s/1o6I2bpw 密碼:7ije
作者:Wolfy
出處:http://www.cnblogs.com/wolf-sun/