【转】AspNetPager分页控件用法

时间:2023-03-08 16:40:16

AspNetPager分页控件解决了分页中的很多问题,直接采用该控件进行分页处理,会将繁琐的分页工作变得简单化,下面是我如何使用AspNetPager控件进行分页处理的详细代码:
1.首先到www.webdiyer.com下载最新的AspNetPager.dll,直接在vs2005中添加引用即可。
2.在页面上注册控件,引入该控件,当然,需要在页面中使用一个数据载体,我这里使用的是repeater控件。

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

<webdiyer:aspnetpager id="AspNetPager1" runat="server" CurrentPageButtonPosition="Center"
    Width="100%"  AlwaysShowFirstLastPageNumber="true" PagingButtonSpacing="10px" FirstPageText="首页"
        LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页" CustomInfoTextAlign="Center"  ShowNavigationToolTip="True" SubmitButtonText="跳" HorizontalAlign="Right" ButtonImageNameExtension="n" CpiButtonImageNameExtension="r"></webdiyer:aspnetpager>

3.cs代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Pager
{
    public partial class Demo_1 : System.Web.UI.Page
    {
        DAL.Books booksdal = new DAL.Books();
        int pagesize = 10;
        protected void Page_Load(object sender, EventArgs e)
        {
           
            if (this.IsPostBack)
            {
            }
            AspNetPager2.RecordCount = 1076;
            Band();
        }

void Band()
        {
            this.Repeater1.DataSource = booksdal.GetTable(pagesize, AspNetPager2.StartRecordIndex,AspNetPager2.EndRecordIndex);
            this.Repeater1.DataBind();

     //public DataTable GetTable(int pagesize,int staindex,int endindex)
        //{
            
        //    string sql = " select top (@pagesize) * from (SELECT ROW_NUMBER() OVER (ORDER BY id) AS RowNumber,* FROM Books ) as A where A.RowNumber between @staindex and @endindex";
        //    SqlParameter[] pars = new SqlParameter[]
        //    {
        //        new SqlParameter("@pagesize",pagesize),
        //        new SqlParameter("@staindex",staindex),
        //        new SqlParameter("@endindex",endindex)
        //    };
           
        //    return DAL.SQL_Help.GetTable(sql, pars);
           
        //}
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            Band();
        }
       
    }
}