前台:
<PagerTemplate>
<asp:Panel id="Panel1" CssClass="panel" runat="server" Width="500px" HorizontalAlign="Left" BackColor="#D6DFF7"
BorderWidth="0px" BorderColor="White" Height="28px">
<asp:Label ID="lblPage" runat="server" Text='<%# "第" + (((GridView)Container.NamingContainer).PageIndex + 1) + "页/共" + (((GridView)Container.NamingContainer).PageCount) + "页" %> '></asp:Label>
<asp:LinkButton ID="first" runat="server" style="text-decoration:none" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' CommandName="Page" CommandArgument="First">首页</asp:LinkButton>
<asp:LinkButton ID="prev" runat="server" style="text-decoration:none" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' CommandName="Page" CommandArgument="Prev">上一页</asp:LinkButton>
<asp:LinkButton ID="next" runat="server" style="text-decoration:none" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' CommandName="Page" CommandArgument="Next">下一页</asp:LinkButton>
<asp:LinkButton ID="last" runat="server" style="text-decoration:none" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' CommandName="Page" CommandArgument="Last">尾页</asp:LinkButton>
<asp:TextBox ID="inPageNum" runat="server" Width="30px"></asp:TextBox>
<asp:Button ID="btnGo" CommandName="go" runat="server" Text="GO" CssClass="btnCss" />
</asp:Panel>
</PagerTemplate>
后台:
protected void grdContent_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "go")
{
try
{
TextBox tb = (TextBox)grdContent.BottomPagerRow.FindControl("inPageNum");
int num = Int32.Parse(tb.Text);
this.grdContent.PageIndex = num - 1;
//绑定数据的方法
BindGridView();
}
catch (Exception ex)
{
throw ex;
}
}
}
protected void grdContent_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.grdContent.PageIndex = e.NewPageIndex;
//绑定数据的方法
SelectWhichDataSource();
}