girdview分页时PageIndexChanging事件问题的解决

时间:2021-05-02

昨天弄了一下午,总是提示激发了未处理的事件“PageIndexChanging“

修改方法:一要在girdview 后面加 OnPageIndexChanging="GridView1_PageIndexChanging,

二要cs页面中添加

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; DataBind(); }

OK问题解决!!

下面的是一个比较齐全的分页代码,

protected void Page_Load(object sender, EventArgs e) { btnFirst.Text = "最首页";btnPrev.Text = "前一页"; btnNext.Text = "下一页";btnLast.Text = "最后页"; GridView1.DataBind();ShowPageChangedStatus(); }

private void ShowPageChangedStatus(){lblCurrentIndex.Text = "第" + (GridView1.PageIndex + 1).ToString() + "页";lblPageCount.Text = "总共 " + GridView1.PageCount.ToString() + " 页";}

public void PagerButtonClick(object sender, EventArgs e) {string arg = ((LinkButton)sender).CommandArgument.ToString();switch (arg){ case "next": if (GridView1.PageIndex < (GridView1.PageCount - 1)) { GridView1.PageIndex += 1; } break; case "prev": if (GridView1.PageIndex > 0) { GridView1.PageIndex -= 1; } break;case "last":GridView1.PageIndex = (GridView1.PageCount - 1); break; default: GridView1.PageIndex = System.Convert.ToInt32(arg); break; } GridView1.DataBind(); ShowPageChangedStatus(); }

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { int startIndex; startIndex = GridView1.PageIndex * GridView1.PageSize; GridView1.PageIndex = e.NewPageIndex; GridView1.DataBind(); ShowPageChangedStatus(); }


<asp:label id="lblPageCount" runat="server"></asp:label> <asp:label id="lblCurrentIndex" runat="server"></asp:label> <asp:linkbutton id="btnFirst" onclick="PagerButtonClick" runat="server" Font-size="8pt" ForeColor="navy" CommandArgument="0"></asp:linkbutton> <asp:linkbutton id="btnPrev" onclick="PagerButtonClick" runat="server" Font-size="8pt" ForeColor="navy" CommandArgument="prev"></asp:linkbutton> <asp:linkbutton id="btnNext" onclick="PagerButtonClick" runat="server" Font-size="8pt" ForeColor="navy" CommandArgument="next"></asp:linkbutton> <asp:linkbutton id="btnLast" onclick="PagerButtonClick" runat="server" Font-size="8pt" ForeColor="navy" CommandArgument="last"></asp:linkbutton>

本文源自:翔宇亭——IT乐园(http://www.biye5u.com),转载请保留此信息!

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章