AspNetPager分页控件教程

前台代码:

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
 <webdiyer:AspNetPager ID="AspNetPager1" CustomInfoHTML="第%CurrentPageIndex%页,共%PageCount%页,每页%PageSize%条" CurrentPageButtonClass="cpb" AlwaysShow="True" runat="server"
            FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页" ShowCustomInfoSection="Left"
            ShowInputBox="Never" OnPageChanging="AspNetPager1_PageChanging" PageIndexBoxType="DropDownList" CustomInfoTextAlign="Left" LayoutType="Table"
            ShowPageIndexBox="Always" SubmitButtonText="Go" PageSize="12" TextAfterPageIndexBox="页"
            TextBeforePageIndexBox="转到" Width="50" Font-Size="X-Small" Height="30">
        </webdiyer:AspNetPager>

前台样式自己写就好了。

后台代码:

protected void Page_Load(object sender, EventArgs e)
    {    
      if (!IsPostBack)
        {
        BindData();
        }
    }
    //获取数据
protected void BindData()
    {

        DataTable dt = PageBysql();
        DataSet ds = new DataSet();
        ds.Tables.Add(dt);
        Pager(this.Repeater1, this.AspNetPager1, ds)}
        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            BindData();
        } 
        protected void Pager(Repeater dl, Wuqi.Webdiyer.AspNetPager anp, System.Data.DataSet dst)
        {
            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = dst.Tables[0].DefaultView;
            pds.AllowPaging = true;
            anp.RecordCount = dst.Tables[0].DefaultView.Count;
            pds.CurrentPageIndex = anp.CurrentPageIndex - 1;
            pds.PageSize = anp.PageSize;
            dl.DataSource = pds;
            dl.DataBind();
        } 

如有不懂的可以私信我!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值