就是在GridView 中写个分布如下:
<PagerTemplate>
<br />
<asp:Label ID="lblPage" runat="server" Text='<%# "第" + (((GridView)Container.NamingContainer).PageIndex + 1) + "页/共" + (((GridView)Container.NamingContainer).PageCount) + "页" %> '></asp:Label>
<asp:LinkButton ID="lbnFirst" runat="Server" Text="首页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' CommandName="Page" CommandArgument="First" ></asp:LinkButton>
<asp:LinkButton ID="lbnPrev" runat="server" Text="上一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' CommandName="Page" CommandArgument="Prev" ></asp:LinkButton>
<asp:LinkButton ID="lbnNext" runat="Server" Text="下一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' CommandName="Page" CommandArgument="Next" ></asp:LinkButton>
<asp:LinkButton ID="lbnLast" runat="Server" Text="尾页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' CommandName="Page" CommandArgument="Last" ></asp:LinkButton>
到第<asp:TextBox runat="server" ID="inPageNum"></asp:TextBox>页 <asp:Button ID="Button1" CommandName="go" CommandArgument="goto" Text="GO" runat="server" /> <br />
</PagerTemplate>
事件中: protected void grdServer_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
//grdServer.PageIndex = e.NewPageIndex-1;
grdServerBangding();
//TextBox tb = (TextBox)grdServer.BottomPagerRow.FindControl("inPageNum");
//tb.Text = (grdServer.PageIndex + 1).ToString();
}
catch
{
}
}
protected void grdServer_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "go")
{
try
{
TextBox tb = (TextBox)grdServer.BottomPagerRow.FindControl("inPageNum");
int num = Int32.Parse(tb.Text);
GridViewPageEventArgs ea = new GridViewPageEventArgs(num - 1);
grdServer_PageIndexChanging(null, ea);
//grdServer.PageIndex = num;
}
catch
{
}
}
if (e.CommandArgument == "First")
{
grdServer.PageIndex = 0;
}
else if (e.CommandArgument == "Next")
{
if (grdServer.PageIndex < grdServer.PageCount - 1)
{
grdServer.PageIndex += 1;
}
}
else if (e.CommandArgument == "Prev")
{
if (grdServer.PageIndex >= 1)
{
grdServer.PageIndex -= 1;
}
}
else if (e.CommandArgument == "Last")
{
grdServer.PageIndex = grdServer.PageCount-1;
}
}
就是老报说什么
把enableEventValidation属性设置为false就可以了