前台页面部分代码:
后台部分代码:
<%@ Page Language="C#" MasterPageFile="~/Common.master" AutoEventWireup="true" CodeFile="AllCategory.aspx.cs" Inherits="AllCategory" Title="" MaintainScrollPositionOnPostback="true" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<%@ register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix="webdiyer" %>//使用aspnetpager控件要引入的命名空间
<div class="fenye">
<webdiyer:aspnetpager id="anp_Pager" runat="server" alwaysshow="True" firstpagetext="第一页"
lastpagetext="最后一页" nextpagetext="下一页" onpagechanged="anp_Pager_PageChanged"
pagesize="5" prevpagetext="上一页" showboxthreshold="2">
</webdiyer:aspnetpager>
</div>
</asp:Content>后台部分代码:
//绑定数据
private void DataBind()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt = BookManager.SelectAllBook();
ds.Tables.Add(dt);
//设置分页
anp_Pager.RecordCount = ds.Tables[0].DefaultView.Count; //记录总数
PagedDataSource pd = new PagedDataSource();
pd.DataSource = ds.Tables[0].DefaultView;
pd.AllowPaging = true; //数据源允许分页
pd.CurrentPageIndex = anp_Pager.CurrentPageIndex - 1; //显示当前页
pd.PageSize = anp_Pager.PageSize; //取控件的分页大小
dlAllBook.DataSource = pd;
dlAllBook.DataBind();
}
//分页事件
protected void anp_Pager_PageChanged(object sender, EventArgs e)
{
DataBind();
}
本文介绍如何在 ASP.NET 应用中使用 Wuqi Webdiyer 的 AspNetPager 控件实现数据分页功能。通过具体示例展示了前台页面与后台代码的结合,包括控件的配置、数据绑定及分页事件处理。
1661

被折叠的 条评论
为什么被折叠?



