自己写的分页方法当gridview的RowEditing事件触发的时候为什么分页的索引也从0开 10
展开全部
第一步:定义一个全局变量保存当前页数和页容量
protected int nCurrentPage
{
get
{
if (ViewState["nCurrentPage"] == null)
return 0;
return (int)ViewState["nCurrentPage"];
}
set { ViewState["nCurrentPage"] = value; }
}
protected int nPageSize = 20;//定义每页条数
第二步:点击上一页,下一页代码:
#region 上一页
protected void btn_up_Click(object sender, ImageClickEventArgs e)
{
if (Pds.CurrentPage > 0)
{
Pds.CurrentPage--;
if (Pds.CurrentPage <= 1)
{
btn_up.Enabled = false;
btn_next.Enabled = true;
}
else
{
btn_up.Enabled = true;
btn_next.Enabled = true;
}
}
else
{
Pds.CurrentPage = 1;
btn_up.Enabled = false;
}
LoadPageSource();
}
#endregion
#region 下一页
protected void btn_next_Click(object sender, ImageClickEventArgs e)
{
btn_up.Enabled = true;
if (Pds.CurrentPage < Pds.PageCount)
{
Pds.CurrentPage++;
}
if (Pds.CurrentPage >= Pds.PageCount)
{
btn_next.Enabled = false;
}
LoadPageSource();
}
#endregion
protected int nCurrentPage
{
get
{
if (ViewState["nCurrentPage"] == null)
return 0;
return (int)ViewState["nCurrentPage"];
}
set { ViewState["nCurrentPage"] = value; }
}
protected int nPageSize = 20;//定义每页条数
第二步:点击上一页,下一页代码:
#region 上一页
protected void btn_up_Click(object sender, ImageClickEventArgs e)
{
if (Pds.CurrentPage > 0)
{
Pds.CurrentPage--;
if (Pds.CurrentPage <= 1)
{
btn_up.Enabled = false;
btn_next.Enabled = true;
}
else
{
btn_up.Enabled = true;
btn_next.Enabled = true;
}
}
else
{
Pds.CurrentPage = 1;
btn_up.Enabled = false;
}
LoadPageSource();
}
#endregion
#region 下一页
protected void btn_next_Click(object sender, ImageClickEventArgs e)
{
btn_up.Enabled = true;
if (Pds.CurrentPage < Pds.PageCount)
{
Pds.CurrentPage++;
}
if (Pds.CurrentPage >= Pds.PageCount)
{
btn_next.Enabled = false;
}
LoadPageSource();
}
#endregion
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询