GridView 分頁

        給你們分享下我自認爲GridView 最簡單的分頁,ide

前臺代碼:server

         <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" >
        <Columns>
            <asp:TemplateField HeaderText="標題"> <ItemTemplate><%# Eval("title") %></ItemTemplate>
                <HeaderStyle HorizontalAlign="Center" Width="200px" />
                <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="產品簡介"> <ItemTemplate><%# Eval("conter") %></ItemTemplate>
                <HeaderStyle HorizontalAlign="Center" />
                <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="下載">
                <ItemTemplate>
                   <a href='<%# Eval("address") %>'>下載</a>
                </ItemTemplate>
                <ControlStyle Font-Bold="True" Font-Overline="True" />
                <HeaderStyle HorizontalAlign="Center" Width="200px" />
                <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>
        </Columns>
        <RowStyle Height="35px" />
    </asp:GridView>字符串

     <div style="float:right">
        <asp:HyperLink ID="HyperLink1" runat="server">首頁</asp:HyperLink>
        <asp:HyperLink ID="HyperLink2" runat="server">上一頁</asp:HyperLink>
        <asp:HyperLink ID="HyperLink3" runat="server">下一頁</asp:HyperLink>
        <asp:HyperLink ID="HyperLink4" runat="server">尾頁</asp:HyperLink>
    </div>get

後臺代碼:產品

          protected void Bind()
        {
            //定義記錄總數
            //int total;
            //定義當前頁碼
            int pageindex;
            //獲取當前頁碼(從查詢字符串中獲取)
            if (!int.TryParse(Request.QueryString["page"], out pageindex))
            {
                pageindex = 1;
            }
            it

            //11爲顯示的當前頁顯示11條記錄。
            //獲取指定類別,指定頁碼的數據,並進行綁定顯示
            GridView1.DataSource = DownManager.GetsPage(pageindex, 11);
            GridView1.DataBind();
            //計算總的頁數
            int totalpage = (int)Math.Ceiling(Convert.ToDouble(DownManager.getsNum()) / 11F);
            //NavigateUrl 獲取或者設置連接目標
            //設置分頁
            HyperLink1.NavigateUrl = "./GoodsDown.aspx?goodsId=" + Request.QueryString["id"];
            HyperLink2.NavigateUrl = "./GoodsDown.aspx?goodsId=" + Request.QueryString["id"] + "&page=" + (pageindex > 1 ? pageindex - 1 : 1);
            HyperLink3.NavigateUrl = "./GoodsDown.aspx?goodsId=" + Request.QueryString["id"] + "&page=" + (pageindex < totalpage ? pageindex + 1 : totalpage);
            HyperLink4.NavigateUrl = "./GoodsDown.aspx?goodsId=" + Request.QueryString["id"] + "&page=" + totalpage;
           
        }class

注:page  id 值的獲取。後臺

相關文章
相關標籤/搜索