这两天公司做了个程序,由于数据比较多,使用分页控件aspNetPager.dll(7.0.2) 控件来分页,比较方便。
不过昨天有人提了个要求,说在修改第十页的数据后,操作完了会自动返回第一页,我再到第十页的时候翻页会比较麻烦。能不能有个方法修改完了,返回的时候还是第十页,这样就方面了很多。刚开始的时候想想很简单么。只要把页数AspNetPager1.CurrentPageIndex保存在session里面 在加载的时候如果session中有值的话就把session中的值设置给AspNetPager1.CurrentPageIndex不就行了么,


(上一页 4 5 6 6 7 8 .... 下一页 )的时候就会出问题,报错(0条数据没法分10页啊,

知道这个道理就简单了,我离开页面之前同时保存CurrentPageIndex 和RecordCount不就行了,下次回来的时候只要这两个值都存在,先绑定RecordCount 告诉它我有这么多条数据,再设定CurrentPageIndex,这样它就可以做分页了,马上修改,搞定!

下面是部分代码:
/// <summary>
/// 保存分页控件的当前页
/// </summary>
public void SaveAspNetPagerIndex()
{
Session["ReceiveListPageIndex"] = AspNetPager1.CurrentPageIndex;
Session["ReceiveListcount"] = AspNetPager1.RecordCount;
}
protected void ANPMember_PageChanged(object sender, EventArgs e)
{
SaveAspNetPagerIndex();
Bind();
}
///在首次加载页面的时候看一下,有没有保存的记录,有就绑定
if (Session["ReceiveListPageIndex"] != null)
{
AspNetPager1.RecordCount = int.Parse(Session["ReceiveListcount"].ToString());
AspNetPager1.CurrentPageIndex = int.Parse(Session["ReceiveListPageIndex"].ToString());
}
注:引用自http://hi.baidu.com/hao_2468/blog/item/d055334d3247fc3dafc3ab92.html
我个人的解决方案用的url传值
来源:https://www.cnblogs.com/wfwup/archive/2009/12/18/1627061.html