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

  • 相关阅读:
    【字符集及字符编码】UTF-8、UTF-16和UTF-32
    【Android】SQLite基本用法(转)
    【eclipse】导入/导出开发环境(包括编辑器字体颜色大小等)
    一个Android Socket的例子(转)
    Linux中与Windows对应的InterlockedIncrement()函数
    Linux互斥锁pthread_mutex_t
    C++读写文本文件
    C++回调函数调用Java接口抽象函数
    Overlapped I/O模型--事件通知【摘录自《Windows网络编程》】
    Linux C++中需要的头文件
  • 原文地址:https://www.cnblogs.com/Kiros/p/1886871.html
Copyright © 2011-2022 走看看