昨天弄了一下午,总是提示激发了未处理的事件“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>
新闻热点
疑难解答
图片精选