您的位置:首页 > 其它

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: