• page分页模板


    <PagerTemplate>
                    当前第:
                    
    //((GridView)Container.NamingContainer)就是为了得到当前的控件
                    <asp:Label ID="LabelCurrentPage" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"></asp:Label>
                    页
    /共:
                    
    //得到分页页面的总数
                    <asp:Label ID="LabelPageCount" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageCount %>"></asp:Label>
                    页
                     
    //如果该分页是首分页,那么该连接就不会显示了.同时对应了自带识别的命令参数CommandArgument
                    <asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page"
                        Visible
    ='<%#((GridView)Container.NamingContainer).PageIndex != 0 %>'>首页</asp:LinkButton>
                    
    <asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev"
                        CommandName
    ="Page" Visible='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>'>上一页</asp:LinkButton>
                   
    //如果该分页是尾页,那么该连接就不会显示了
                    <asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
                        Visible
    ='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>下一页</asp:LinkButton>
                    
    <asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
                        Visible
    ='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>尾页</asp:LinkButton>
                    转到第
                    
    <asp:TextBox ID="txtNewPageIndex" runat="server" Width="20px" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />
                    
    //这里将CommandArgument即使点击该按钮e.newIndex 值为3 
                    <asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-2"
                        CommandName
    ="Page" Text="GO" />
                
    </PagerTemplate>

    后台代码

     1    protected void gvwDesignationName_PageIndexChanging(object sender, GridViewPageEventArgs e)
     2     {
     3         // 得到该控件
     4         GridView theGrid = sender as GridView;
     5         int newPageIndex = 0;
     6         if (e.NewPageIndex == -3)
     7         {
     8             //点击了Go按钮
     9             TextBox txtNewPageIndex = null;
    10 
    11             //GridView较DataGrid提供了更多的API,获取分页块可以使用BottomPagerRow 或者TopPagerRow,当然还增加了He          aderRow和FooterRow
    12             GridViewRow pagerRow = theGrid.BottomPagerRow;
    13 
    14             if (pagerRow != null)
    15             {
    16                 //得到text控件
    17                 txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;
    18             }
    19             if (txtNewPageIndex != null)
    20             {
    21                 //得到索引
    22                 newPageIndex = int.Parse(txtNewPageIndex.Text) - 1;
    23             }
    24         }
    25         else
    26         {
    27             //点击了其他的按钮
    28             newPageIndex = e.NewPageIndex;
    29         }
    30         //防止新索引溢出
    31         newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
    32         newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
    33 
    34         //得到新的值
    35         theGrid.PageIndex = newPageIndex;
    36 
    37         //重新绑定
    38         BindReport(0);
    39     }
  • 相关阅读:
    List 与 Array 的相互转化及 List、Array、Set转为 String
    Java 序列化介绍及 Redis 序列化方式
    SpringBoot 整合 redis 实现 token 验证
    SpringBoot 整合 Redis 使用
    Map 某 value 为 对象数组,转为 ArrayList 对象集合
    JWT 基本使用
    Spring session + redis 实现 session共享入门
    HttpServletRequest + Filter 添加 header
    Git ahead(超前) 又behind(落后)
    web应用中路径跳转问题-相对路径、绝对路径
  • 原文地址:https://www.cnblogs.com/dongbo19910728/p/3222506.html
Copyright © 2020-2023  润新知