<PagerTemplate>
<table>
<tr>
<td>
<asp:Label ID="LabelCurrentPage" runat="server"
>当前页:<%# ((GridView)Container.NamingContainer).PageIndex + 1 %></asp:Label></td>
<td>
<asp:Label ID="LabelPageCount" runat="server" >总页数:<%# ((GridView)Container.NamingContainer).PageCount %></asp:Label></td>
<td>
<asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page"
Enable="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">首页</asp:LinkButton></td>
<td>
<asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev" CommandName="Page"
Enable="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">上一页</asp:LinkButton></td>
<td>
<asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
Enable="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">下一页</asp:LinkButton></td>
<td>
<asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
Enable="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">尾页</asp:LinkButton></td>
</tr>
</table>
</PagerTemplate>
把以上表格放到<PagerTemplate>即可
1. 默认分页方式
(1) 是否允许分页
GridView 的 AllowPaging 属性。
(2) 每页记录数
GridView 的 PageSize
(3) 分页导航条形式
GridView 的 PagerSettings 属性的 Mode : Numeric , NextPrevious , NextPreviousFirstLast , NumericFirstLast 。
2. 自定义分页
( 1) 当前页
Text ="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"></ asp:Label >
(2) 总页数
Text ="<%# ((GridView)Container.NamingContainer).PageCount %>"></ asp:Label >
(3) 首页、上一页、下一页、尾页
Visible ="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>"> 首页 </ asp:LinkButton >
< asp:LinkButton ID ="LinkButtonPreviousPage" runat ="server" CommandArgument ="Prev" CommandName ="Page"
Visible ="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>"> 上一页 </ asp:LinkButton >
< asp:LinkButton ID ="LinkButtonNextPage" runat ="server" CommandArgument ="Next" CommandName ="Page"
Visible ="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>"> 下一页 </ asp:LinkButton >
< asp:LinkButton ID ="LinkButtonLastPage" runat ="server" CommandArgument ="Last" CommandName ="Page"
Visible ="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>"> 尾页 </ asp:LinkButton >
<asp:linkbutton id="btnGo" runat="server" causesvalidation="False" commandargument="-1" commandname="Page" text="GO" />