zoukankan      html  css  js  c++  java
  • GridView 手写分页 初级

    今天研究这个研究了半天,初步了解了GridView自动分页是如何操作的 话不多 贴代码、

     <PagerTemplate>
                        <asp:LinkButton ID="lbFirst" runat="server" CausesValidation="False" CommandArgument="First"
                            CommandName="Page">First</asp:LinkButton>
                        <asp:LinkButton ID="lbPrev" runat="server" CausesValidation="False" CommandArgument="Prev"
                            CommandName="Page">Prev</asp:LinkButton>
                        <asp:LinkButton ID="lbNext" runat="server" CausesValidation="False" CommandArgument="Next"
                            CommandName="Page">Next</asp:LinkButton>
                        <asp:LinkButton ID="lbLast" runat="server" CausesValidation="False" CommandArgument="Last"
                            CommandName="Page">Last</asp:LinkButton>
                        第<asp:Label ID="Label2" runat="server" Text="<%#((GridView)Container.Parent.Parent).PageIndex + 1 %>"></asp:Label>页
                        共<asp:Label ID="Label1" runat="server" Text="<%# ((GridView)Container.Parent.Parent).PageCount %>"></asp:Label>页
                        跳到<asp:TextBox ID="tbPage" runat="server" Text="<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>"
                            Width="27px"></asp:TextBox>
                        <asp:LinkButton ID="lbGO" runat="server" CausesValidation="False" CommandArgument="0"
                            CommandName="Page" Text="GO"></asp:LinkButton>
     </PagerTemplate>

    //添加PageIndexChanging事件  注意:这个是必须的

     protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView gvw = (GridView)sender;
            if (e.NewPageIndex < 0)
            {
                TextBox pageNum = (TextBox)gvw.BottomPagerRow.FindControl("tbPage");
                int Pa = int.Parse(pageNum.Text);
                if (Pa <= 0)
                    gvw.PageIndex = 0;
                else
                    gvw.PageIndex = Pa - 1;
            }
            else
            {
                gvw.PageIndex = e.NewPageIndex;
            }
            GridView_Bind();
        }

    <%#((GridView)Container.Parent.Parent).PageIndex + 1 %>  显示当前页

  • 相关阅读:
    python!让人惊讶的python
    由测试中的版本同步联想到敏捷开发中的两个实践
    python中比较两个文件是否相同
    python中根据类名生成类的实例
    使用sqlServer开发应用程序时要注意的10件事
    python版的Hello World
    其他语言的.net实现列表
    Bug管理的流程和几个重点
    IL Reference
    Delphi CreateProcess函数调用示例
  • 原文地址:https://www.cnblogs.com/Kiros/p/1886871.html
Copyright © 2011-2022 走看看