GridView 分页功能中指定跳转页的值怎么改不了?求大虾教教额!!!

2025-05-13 23:03:39
推荐回答(1个)
回答1:

这位兄台 你的page_load事件里面 添加了if(!isPostback)了 吗 如
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridViewTableDataBind();
}
}如果你没加上去 你每次点跳转到""页的时候值都为空 以下是我的分页部分的代码
Text='<%# "第" + (((GridView)Container.NamingContainer).PageIndex + 1) + "页/共" + (((GridView)Container.NamingContainer).PageCount) + "页" %> '>
CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>"
OnClientClick="__doPostBack('lbnFirst','First')" Text="首页">

CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>"
Text="上一页">

CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>"
Text="下一页">

CommandName="Page"
Enabled="<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>"
Text="尾页">

到第




后台
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
MessListDataBind();
}
}
public void MessListDataBind()
{
gv1.DataSource = BLL.GetMessList.GetMSList();
gv1.DataBind();

}
protected void gv1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gv1.PageIndex = e.NewPageIndex;
gv1.DataSource = BLL.GetComNew.GetComNews();
gv1.DataBind();

}
protected void LinkPage(object sender, EventArgs e)
{

TextBox tb = (TextBox)gv1.BottomPagerRow.FindControl("inPageNum");
if (tb.Text == null || tb.Text == "")
{
tb.Text = "1";
}
gv1.PageIndex = Convert.ToInt32(tb.Text.ToString());
gv1.DataSource = BLL.GetComNew.GetComNews();
gv1.DataBind();

}