GridView自定义分页

比较懒的一种方法.
GridView设置为允许分页,然后编辑Pager模板,随便输点东西,结束模板编辑.
然后再源代码中用下面的Table替换
<PagerTemplate>
                
<table>
                    
<tr>
                        
<td>
                            
<asp:Label ID="LabelCurrentPage" runat="server">&nbsp;<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>&nbsp;页</asp:Label></td>
                        
<td>
                            
<asp:Label ID="LabelPageCount" runat="server">&nbsp;<%# ((GridView)Container.NamingContainer).PageCount %>&nbsp;页</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
posted @ 2008-01-25 17:22  林杰的博客  阅读(552)  评论(2编辑  收藏  举报