Gridview自定义分页

  在这里我使用Gridview中自带的分页,然后进行扩展,代码如下:

 <PagerTemplate>
                            <div class="divPager">
                                第<asp:Label ID="lblCurrrentPage" runat="server" ForeColor="Red" Text="<%#(((GridView)Container.NamingContainer).PageIndex + 1) %>"></asp:Label>页
                                /共<asp:Label ID="lblPageCount" runat="server" CssClass="Counts" Text="<%#(((GridView)Container.NamingContainer).PageCount) %>" />页
                                <asp:LinkButton ID="lbnFirst" runat="Server" Text="首页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>'
                                    CommandName="Page" CommandArgument="First"></asp:LinkButton>
                                <asp:LinkButton ID="lbnPrev" runat="server" Text="上一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>'
                                    CommandName="Page" CommandArgument="Prev"></asp:LinkButton>
                                <asp:LinkButton ID="lbnNext" runat="Server" Text="下一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>'
                                    CommandName="Page" CommandArgument="Next"></asp:LinkButton>
                                <asp:LinkButton ID="lbnLast" runat="Server" Text="尾页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>'
                                    CommandName="Page" CommandArgument="Last"></asp:LinkButton>
                                到第<asp:TextBox runat="server" ID="inPageNum" Width="50" MaxLength="5"></asp:TextBox>页<asp:Button
                                    ID="Button1" CommandName="go" runat="server" Text="Go" />
                            </div>
                            <div class="divPageSize">
                                每页显示记录数:<asp:TextBox ID="txtPageSize" runat="server" Width="25" MaxLength="3"></asp:TextBox><asp:Button
                                    ID="btnSetPageSize" runat="server" Text="设置" CommandName="SetPageSize" />
                            </div>
                            <div style="float: left">
                                <span>总车载机数量:<asp:Label ID="lblCounts" runat="server" Text='' CssClass="Counts"></asp:Label></span>
                                <span>在线车载机数量:<asp:Label ID="lblOnlineCounts" runat="server" Text="" CssClass="Counts"></asp:Label></span>
                                <span>当天连上车载机数量:<asp:Label ID="lblCurrentOnlineCount" runat="server" Text="" CssClass="Counts"></asp:Label></span></div>
                        </PagerTemplate>
后台代码如下:

  protected void gvEquData_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            switch (e.CommandName)
            {
                case "go":
                    WebTextBox tb = (WebTextBox)gvEquData.TopPagerRow.FindControl("inPageNum");
                    if (CommonClass.StrIsInt(tb.Text.Trim()))
                    {
                        int num = Int32.Parse(tb.Text.Trim());
                        GridViewPageEventArgs ea = new GridViewPageEventArgs(num - 1);
                        gvEquData_PageIndexChanging(null, ea);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "ErrorInfo", "<script>alert('输入格式有误!请重新输入');</script>", false);
                        BindGridViewData();
                    }
                    break;
                case "SetPageSize":
                    WebTextBox tb2 = (WebTextBox)gvEquData.TopPagerRow.FindControl("txtPageSize");
                    string strPageSize = tb2.Text.Trim();
                    if (CommonClass.StrIsInt(strPageSize)) //&& int.Parse(strPageSize) > 0 && int.Parse(strPageSize) <= EquSearchBll.equBll.GetRows()
                    {
                        AppconfigClass.SetValue("EquPageSize", strPageSize);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "ErrorInfo", "<script>alert('输入格式有误!请重新输入');</script>", false);
                    }
                    BindGridViewData();
                    break;
                default:
                    break;
            }
        }
        catch (Exception ex)
        {
            CommonClass.WriteExceptionInfo(ex.Message);
        }
    }


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

邹琼俊

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

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

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

打赏作者

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

抵扣说明:

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

余额充值