前台页面部分代码: <%@ 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(); }