• Gridview 分页,OnPageIndexChanging事件(转)


    Gridview 分页,OnPageIndexChanging事件

    1. 默认分页方式 
    (1) 是否允许分页 
    GridView的AllowPaging属性。

    (2) 每页记录数 
    GridView的PageSize

    (3) 分页导航条形式 
    GridView的PagerSettings属性的Mode:Numeric,NextPrevious,NextPreviousFirstLast,NumericFirstLast。

    aspx:
    <asp:GridView ID="gv" AllowPaging="True" OnPageIndexChanging="gv_OnPageIndexChanging" PageSize="5" runat="server">
    </asp:GridView>

    cs:
    protected void gv_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.gv.PageIndex = e.NewPageIndex;
        this.gvbind(); //重新绑定GridView数据的函数
    }

    2. 自定义分页 
    (1) 当前页 总页数 首页、上一页、下一页、尾页  跳转到[ ]页
     <PagerTemplate>
    -- [当前第 <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> 页] --

    <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 %>' />
    <asp:linkbutton id="btnGo" runat="server" causesvalidation="False" commandargument="-1" commandname="Page" text="GO" /> 
    </PagerTemplate>          protected void gv_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
     {
            GridView theGrid = sender as GridView;
            int newPageIndex = 0;
            if (-2 == e.NewPageIndex)
            { 
                TextBox txtNewPageIndex = null;
                GridViewRow pagerRow = theGrid.BottomPagerRow; 
                if (null != pagerRow)
                {
                    txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;   
                }
                if (null != txtNewPageIndex)
                {
                    newPageIndex = int.Parse(txtNewPageIndex.Text) - 1; // get the NewPageIndex
                }
            }
            else
            { newPageIndex = e.NewPageIndex;}
            newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
            newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
            theGrid.PageIndex = newPageIndex;
    }

     
  • 相关阅读:
    Ajax的个人总结
    JSON和计算机网络的个人总结
    Bootstrap内辅助类,响应式工具,组件的个人总结
    Bootstrap内栅格布局,表格,按钮,图片的个人总结
    [BUG] Linux font family error #153
    WPF在WindowStyle=None时去掉顶部白条
    WPF 之 左键弹出操作菜单,并禁用右键菜单
    WPF 气泡提示框的简单实现
    WPF TextBox 如何简单粗暴的实现水印效果?
    c#笔记--WPF文本框和密码框添加水印效果(背景文字提示)
  • 原文地址:https://www.cnblogs.com/wandd/p/3100959.html
Copyright © 2020-2023  润新知