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/