GridView自定义分页
2008-01-25 17:22
435 查看
比较懒的一种方法.
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>
注意要添加PageIndexChanging事件,代码如下
protected void grv_items_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//处理分页事件
grv_items.PageIndex = e.NewPageIndex;
//绑定数据代码
}
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>
注意要添加PageIndexChanging事件,代码如下
protected void grv_items_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//处理分页事件
grv_items.PageIndex = e.NewPageIndex;
//绑定数据代码
}
OK
相关文章推荐
- 自定义GridView分页模板
- GridView 批量删除,自定义分页,定位页码
- 简单的GridView自定义分页
- 关于VS2005中GridView的自定义分页,单选、多选、排序、自增列的简单应用
- Gridview自定义分页
- GridView自定义分页
- GridView自定义分页
- GridView自定义分页(vb)
- GridView的自定义分页,单选、多选、排序、自增列的简单应用
- 自定义GridView分页样式
- 关于GridView中自定义分页、单选、多选的简单应用(原创)
- 转载GridView控件自定义分页详解
- gridview自定义分页 aspNetPager用法
- GridView自定义分页
- GridView 自定义分页
- GridView分页的实现以及自定义分页样式功能实例
- GridView自定义分页
- ASP.NET GridView自定义分页的方法
- GridView 实现自定义分页、排序、查询、添加、编辑、多选删除、导出、突出显示等常见应用实现(cs)
- GridView实战一:自定义分页、排序、修改、插入、删除