使用List集合做数据源,并且使用AspNetPager来分页

AspNetPager 控件使用时,第一步就要在

if (!IsPostBack)
        {
              AspNetPager1.RecordCount =数据源记录总数;

            //bindData(); //使用url分页,只需在分页事件处理程序中绑定数据即可,无需在Page_Load中绑定,否则会导致数据被绑定两次
        }

第二步就是在 绑定数据源时,指定数据源中开始记录的索引与结束记录的索引,这样就可使用了

void bindData()

{

  Repeater1.DataSource = SqlHelper.ExecuteReader(CommandType.StoredProcedure, ConfigurationManager.AppSettings["pagedSPName"],
            new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),
            new SqlParameter("@endIndex", AspNetPager1.EndRecordIndex));
        Repeater1.DataBind();

}

问题:如果是用集合来做数据源,怎么办?处理办法利用PagedDataSource做数据源

假设下面例子getdata()返回的是泛型list

 void bind()
    {
       this.AspNetPager1.PageSize = 5;//分页控件每页显示记录数
       this.AspNetPager1.RecordCount = getdata().Count;//分页控件要显示数据源的记录总数
     
        PagedDataSource pds = new PagedDataSource ();//数据源分页
        pds.DataSource = getdata();//得到数据源
        pds.AllowPaging = true;//允许分页
        pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;//当前分页数据源的页面索引
        pds.PageSize = AspNetPager1.PageSize;//分页数据源的每页记录数
        this.Repeater1.DataSource = pds;//指定为控件数据源
        this.Repeater1.DataBind();
     
           }

本文来自:奎宇工作室

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23109131/viewspace-705186/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/23109131/viewspace-705186/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值