DataList分页(用AspNetPager控件)

AspNetPager支持两种方式分页:
一种是PostBack方式分页,一种是通过Url来实现分页以及Url重写功能
AspNetPager支持各种数据绑定控件GridView、DataGrid、DataList、Repeater以及自定义的数据绑定控件的分页功能十分强大。
AspNetPager分页控件本身并不显示任何数据,而只显示分页导航元素,数据在页面上的显示方式与该控件无关,所以需要手写数据连接方法来配合,
结合TOP 。。。NOT IN 的通用存储过程分页方法使用AspNetPager十分实用

测试控件datalist aspnetpager 的分页方法示例   分页方法为 PostBack 方式
1、 首先将AspNetPager.dll复制于应用程序下的bin目录,打开解决方案,引入dll文件

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


2、 在工具栏中添加控件,这样可以支持拖拽使用
3、  要使用AspNetPager 要为其设置最基本的属性

控件下载地址:

 http://www.webdiyer.com/Controls/AspNetPager/Downloads

CSS:

 <style type="text/css">
.anpager .cpb {background:#4BB0DE none repeat scroll 0 0;border:1px solid #CCCCCC;color:#FFFFFF;font-weight:bold;margin:5px 4px 0 0;padding:4px 5px 0;}

.anpager a {background:#FFFFFF none repeat scroll 0 0;border:1px solid #CCCCCC;color:#1F3A87;margin:5px 4px 0 0;padding:4px 5px 0;text-decoration:none}
.anpager a:hover{background:#8BD0F6 none repeat scroll 0 0;border:1px solid #1F3A87;color:#FFFFFF;}
  </style>


 

 

 

 <webdiyer:AspNetPager Width="99%" ID="AspNetPager1" MoreButtonType="Text" PagingButtonType="Text"
                        PageSize="15" AlwaysShow="false" runat="server" SubmitButtonText="Go" HorizontalAlign="Right"
                        ShowCustomInfoSection="Right" CustomInfoHTML="共%PageCount%页,每页%PageSize%条"
                        OnPageChanged="AspNetPager1_PageChanged" NextPageText="下一页" FirstPageText="首页"
                        LastPageText="尾页" PageIndexBoxType="TextBox" PrevPageText="上一页" ShowPageIndexBox="Always"
                        TextAfterPageIndexBox="页" TextBeforePageIndexBox="转到" CssClass="anpager" CurrentPageButtonClass="cpb"
                        CustomInfoSectionWidth="220px" Height="13px">
                    </webdiyer:AspNetPager>

 

 

后台主要代码:

 private void show() 
    {
        string splb = splbbh;
        string pszx = ddlpszx.SelectedValue;
       
        string strsql = "sql语句”;
        DataTable dt = db.ds_sql(strsql).Tables[0];
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = dt.DefaultView;
        pds.AllowPaging = true;
        pds.PageSize = this.AspNetPager1.PageSize;
      
        this.AspNetPager1.RecordCount = (int)pds.DataSourceCount;
        pds.CurrentPageIndex = this.AspNetPager1.CurrentPageIndex-1;
        LbRecordCount.Text = pds.DataSourceCount.ToString();
        dllist.DataSource = pds;
        dllist.DataBind();

    }
 
 protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        show();
    }


效果图:

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值