gridview 高级分页

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            DataSourceID="SqlDataSource1" Width="449px" OnRowDataBound="GridView1_RowDataBound" CellPadding="4" ForeColor="#333333" GridLines="None" AllowSorting="True" OnRowCreated="GridView1_RowCreated" AllowPaging="True" OnPageIndexChanged="GridView1_PageIndexChanged" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowCommand="GridView1_RowCommand">
            <Columns>
                <asp:BoundField DataField="pkiib" HeaderText="档号" SortExpression="pkiib" >
                    <ItemStyle VerticalAlign="Middle" Width="50px" />
                </asp:BoundField>
                <asp:HyperLinkField DataNavigateUrlFields="pkiib" DataNavigateUrlFormatString="left.aspx?pkiib={0}"
                    DataTextField="pkiia" NavigateUrl="~/left.aspx" Target="left" HeaderText="报告标题" >
                    <HeaderStyle VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Left" />
                </asp:HyperLinkField>
                <asp:BoundField DataField="pkiia" HeaderText="隐藏字段" SortExpression="pkiia" Visible="False" >
                    <HeaderStyle VerticalAlign="Middle" />
                </asp:BoundField>
                <asp:HyperLinkField DataNavigateUrlFields="pkiib" DataNavigateUrlFormatString="~/PDFWeb/Default.aspx?pkiib={0}"
                    HeaderText="电子文档" NavigateUrl="~/PDFWeb/Default.aspx" Target="_blank" Text="图文浏览" >
                    <ItemStyle Width="80px" />
                </asp:HyperLinkField>
            </Columns>
            <PagerTemplate>
<asp:LinkButton ID="btnFirst" runat="server" CausesValidation="False" CommandArgument="First" CommandName="Page" ForeColor="White">首页</asp:LinkButton>
<asp:LinkButton ID="btnPrev" runat="server" CausesValidation="False" CommandArgument="Prev" CommandName="Page" ForeColor="White">上一页</asp:LinkButton>
<asp:LinkButton ID="btnNext" runat="server" CausesValidation="False" CommandArgument="Next" CommandName="Page" ForeColor="White">下一页</asp:LinkButton>
<asp:LinkButton ID="btnLast" runat="server" CausesValidation="False" CommandArgument="Last" CommandName="Page" ForeColor="White">尾页</asp:LinkButton>
第<asp:Label ID="lbpage" runat="server" Text=" <%#((GridView)Container.Parent.Parent).PageIndex + 1 %>"> </asp:Label>页共<asp:Label ID="lbpagecount" runat="server" Text=" <%# ((GridView)Container.Parent.Parent).PageCount %>"></asp:Label>页<asp:TextBox ID="txtPage" runat="server" Text=" <%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>" Width="27px"></asp:TextBox>
<asp:LinkButton ID="btnGO" runat="server" CausesValidation="False" CommandArgument="-1" CommandName="Page" Text="GO" ForeColor="Red"></asp:LinkButton>
</PagerTemplate>


            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#EFF3FB" />
            <EditRowStyle BackColor="#2461BF" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
            <PagerSettings FirstPageText="首页" LastPageText="末页" NextPageText="下一页" PreviousPageText="上一页" />
        </asp:GridView>

 

 

  protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Page")
        {
            if (e.CommandArgument == "-1")
            {
                try
                {
                    int page = Convert.ToInt32(((TextBox)GridView1.BottomPagerRow.FindControl("txtPage")).Text.ToString()) - 1;
                    Session["pagesize"] = page;
                }
                catch (Exception)
                {
                    Session["pagesize"] = 0;
                }
            }else
                Session["pagesize"] = 0;
        }

    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        int pagesize;
        if (Session["pagesize"] == "")
        {
            if (e.NewPageIndex < 0)
            {
                pagesize = 0;
            }
            else
            {
                if (e.NewPageIndex > GridView1.PageCount - 1)
                {
                    pagesize = GridView1.PageCount - 1;
                }
                else
                {
                    pagesize = e.NewPageIndex;
                }
            }
        }
        else
        {
            pagesize = Convert.ToInt32(Session["pagesize"].ToString());
            Session["pagesize"] = "";

        }
        //BindGridView(pagesize);//绑定GridView数据
        if (pagesize < 0)
            pagesize = 0;
        GridView1.PageIndex = pagesize;
    }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

开发软件店

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值