• 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 %>  显示当前页

  • 相关阅读:
    win7下面安装VC6的SP5补丁
    共享一下, 国家授时中心服务器的IP地址
    修改默认调试器
    在做系统分析时,用到的几种对象之间的关系
    About SetClientSite in ActiveX
    我常用的Windbg命令
    字符编码笔记:ASCII,Unicode和UTF8(转) + BASE64
    Google Earth
    4.用条件属性而不是#if
    1.尽可能的使用属性,而不是数据成员
  • 原文地址:https://www.cnblogs.com/Kiros/p/1886871.html
Copyright © 2020-2023  润新知