前台
//<reapeater>
//</reapeater>
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" CustomInfoHTML="共%PageCount%页%RecordCount%个数据,当前为第%CurrentPageIndex%页,每页%PageSize%条"
FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页"
ShowBoxThreshold="1" ShowCustomInfoSection="Right" Width="100%"
OnPageChanging="AspNetPager1_PageChanged" PageSize="2">
</webdiyer:AspNetPager>
后台
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
AspNetPager1.CurrentPageIndex = 1;
BindUserList(true);
}
}
/// <summary>
/// 绑定列表数据
/// </summary>r
protected void BindUserList(bool reloadRecordCount)
{
//BindControl bindC = new BindControl();
//bindC.BindBoundControl<Entities.Sys_User>(users.GetAllUsers().OrderBy(v => v.UID), this.rpt_list, 1);
if (reloadRecordCount)
{
AspNetPager1.RecordCount = users.GetAllUsers().Count();
}
rpt_list.DataSource = users.GetAllUsers().Skip((AspNetPager1.CurrentPageIndex - 1) * AspNetPager1.PageSize).Take(AspNetPager1.PageSize);
rpt_list.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
BindUserList(false);
}
问题主要是,页是可以分。但点击下一页,或是首页。数据显示很混乱,第一条数据一会在第一页,一会在最后一页
在AspNetPager的PageChanging事件里需要指定AspNetPager的当前页:
protected void AspNetPager1_PageChanged(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
LoadData();
}
if (AspNetPager1.RecordCount == 0) AspNetPager1.RecordCount =db.users.Count(); var gaga= (from i in db.users orderby i.InDate descending select i).Skip(AspNetPager1.StartRecordIndex - 1).Take(AspNetPager1.PageSize); AspNetPager1.DataSource = gaga; AspNetPager1.DataBind();