GridView自定义分页
比较懒的一种方法.
GridView设置为允许分页,然后编辑Pager模板,随便输点东西,结束模板编辑.
然后再源代码中用下面的Table替换
注意要添加PageIndexChanging事件,代码如下
OK
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
本文基于署名 2.5 中国大陆许可协议发布,欢迎转载,演绎或用于商业目的,但是必须保留本文的署名和链接(http://greenerycn.cnblogs.com).
如果觉得文章有用,愿意的话赞助一杯饮料吧,谢谢。