GridView设置为允许分页,然后编辑Pager模板,随便输点东西,结束模板编辑.
然后再源代码中用下面的Table替换
<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"
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">首页</asp:LinkButton></td>
<td>
<asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev"
CommandName="Page"
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">上一页</asp:LinkButton></td>
<td>
<asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">下一页</asp:LinkButton></td>
<td>
<asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">尾页</asp:LinkButton></td>
</tr>
</table>
</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"
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">首页</asp:LinkButton></td>
<td>
<asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev"
CommandName="Page"
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">上一页</asp:LinkButton></td>
<td>
<asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">下一页</asp:LinkButton></td>
<td>
<asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">尾页</asp:LinkButton></td>
</tr>
</table>
</PagerTemplate>
注意要添加PageIndexChanging事件,代码如下
protected void grv_items_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//处理分页事件
grv_items.PageIndex = e.NewPageIndex;
//绑定数据代码
}
{
//处理分页事件
grv_items.PageIndex = e.NewPageIndex;
//绑定数据代码
}
OK
332

被折叠的 条评论
为什么被折叠?



