[转]datapager分页问题(点击两次)
2012-10-25 14:56
309 查看
今天看了一下ListView和DataPager配合做数据分页的教程,感觉很爽很方便,用在自己的项目上面时却出现了问题,具体表现在点击上一页、下一页或者数字跳转页面时通常要点两下才能有反应,而且有时候乱跳页。
我开始测试的代码是这样的:
出现如开始提及的问题,找了半天原因也没有找到。后来在国外的一个论坛上找到了同病相怜的人,有专家给出了一个解决方案。把Page_Load里的数据绑定移到Page_PreRender中,也就是:
试了一下分页果然正常了。难道是Page_Load来的太迟?不得而知。另外,还有一种方法同样可行:
我开始测试的代码是这样的:
public partial class ListViewTest : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) BindData(); } protected void BindData() { DBDataContext db = new DBDataContext(); var ds = db.Category; ListView1.DataSource = ds; ListView1.DataBind(); db.Dispose(); } }
出现如开始提及的问题,找了半天原因也没有找到。后来在国外的一个论坛上找到了同病相怜的人,有专家给出了一个解决方案。把Page_Load里的数据绑定移到Page_PreRender中,也就是:
public partial class ListViewTest : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //if (!Page.IsPostBack) // BindData(); } protected void Page_PreRender(object sender, EventArgs e) { BindData(); } protected void BindData() { DBDataContext db = new DBDataContext(); var ds = db.Category; ListView1.DataSource = ds; ListView1.DataBind(); db.Dispose(); } }
试了一下分页果然正常了。难道是Page_Load来的太迟?不得而知。另外,还有一种方法同样可行:
public partial class ListViewTest : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) BindData(); } protected void Page_PreRender(object sender, EventArgs e) { //BindData(); } protected void ListView1_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e) { DataPager1.SetPageProperties(e.StartRowIndex, e.MaximumRows, false); BindData(); } protected void BindData() { DBDataContext db = new DBDataContext(); var ds = db.Category; ListView1.DataSource = ds; ListView1.DataBind(); db.Dispose(); } }
相关文章推荐
- datapager分页问题 (点击两次)
- datapager分页问题(点击两次) (转)
- datapager分页问题(点击两次)
- datapager分页问题 (点击两次)
- c# 中 datapager分页问题 (点击两次) 并且有错误提示
- datapager分页问题(点击两次)
- datapager分页问题(点击两次)
- Asp.net DataPager 分页点两次的问题
- DataPager分页问题,ListView重新绑定数据源后DataPager未回到初始页?
- 解决GridView控件分页点击两次问题
- 当一些按钮:比如button或者分页控件需要点击两次才起作用问题
- vs2008中datapager分页问题的解决方法,用好的解决方法的请留言
- 解决EditText点击两次才能输入的问题
- Extjs 4.2 grid 分页问题,点击下一页参数没带过去
- [学习笔记][ASP.NET2.0][点击asp:Button出现两次提交数据的问题][解决:去掉OnClick或者OnCommand属性]
- 使用DataPager 显示记录数,分页
- 处理频繁点击问题, 如果两次点击小于500毫秒则不予以响应
- ASP.NET使用ListView数据绑定控件和DataPager实现数据分页显示(一)
- ListView中嵌套Repeater,且DataPager分页
- Element-UI分页组件连续点击后页码循环跳转问题解决方案