datapager分页问题(点击两次)
2011-04-24 15:30
429 查看
本文来自:http://www.cnblogs.com/it563/articles/1345059.html
今天看了一下ListView和DataPager配合做数据分页的教程,感觉很爽很方便,用在自己的项目上面时却出现了问题,具体表现在点击上一页、下一页或者数字跳转页面时通常要点两下才能有反应,而且有时候乱跳页。
我开始测试的代码是这样的:
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();
}
}
参考:/article/6226123.html
今天看了一下ListView和DataPager配合做数据分页的教程,感觉很爽很方便,用在自己的项目上面时却出现了问题,具体表现在点击上一页、下一页或者数字跳转页面时通常要点两下才能有反应,而且有时候乱跳页。
我开始测试的代码是这样的:
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();
}
}
参考:/article/6226123.html
相关文章推荐
- c# 中 datapager分页问题 (点击两次) 并且有错误提示
- datapager分页问题 (点击两次)
- datapager分页问题(点击两次)
- datapager分页问题(点击两次)
- datapager分页问题(点击两次) (转)
- datapager分页问题 (点击两次)
- [转]datapager分页问题(点击两次)
- Asp.net DataPager 分页点两次的问题
- DataPager分页问题,ListView重新绑定数据源后DataPager未回到初始页?
- 解决GridView控件分页点击两次问题
- 当一些按钮:比如button或者分页控件需要点击两次才起作用问题
- vs2008中datapager分页问题的解决方法,用好的解决方法的请留言
- 分页解决方案 —— GridView + QuickPager + QuickPager_SQL + DataAccessLibrary + 数据库
- 使用Spring Data Jpa 遇到 数据库字段以 from 开头,分页查询失败的问题
- 解决使用 clipboard.js 复制内容点击两次才能成功问题
- 解决ViewPager嵌套Fragment内部点击事件无响应问题
- WEUI点击事件执行两次的问题解决
- 按钮点击不起作用和点击一次执行两次问题解决
- 关于Button点击两次才响应事件相关问题
- 解决 android设置软键盘搜索键以及监听搜索键点击时发生两次事件的问题