Webform gridView分页

分页详解:
从工具栏中拖拽Gridview数据控件;
(1)设置数据 AllowPaging=”True”;并自定义每页显示的数目 PageSize=”10”;
同时设置页索引改变事件:OnPageIndexChanging=“GridView1_PageIndexChanging”

 protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;
            DataBind();
        }

(2)接下来添加分页模板

//在该模板里面定义分页相应的按钮
<PagerTemplate>
 <table style="font-size: 12px; width: 100%;">
                        <tr>
                            <td style="text-align: right"><asp:Label ID="lblPageIndex" runat="server" Text="<%#((GridView)Container.Parent.Parent).PageIndex+1 %>"></asp:Label>页
                                /共<asp:Label ID="lblPageCount" runat="server" Text="<%#((GridView)Container.Parent.Parent).PageCount %>"></asp:Label>页&nbsp;&nbsp;
                                <asp:LinkButton ID="lbFirstPage" runat="server" CommandArgument="First" CommandName="Page" Visible="<%#((GridView)Container.Parent.Parent).PageIndex!=0 %>">首页</asp:LinkButton>
                                <asp:LinkButton ID="lbPrevPage" runat="server" CommandArgument="Prev" CommandName="Page" Visible="<%#((GridView)Container.Parent.Parent).PageIndex!=0 %>">上一页</asp:LinkButton>
                                <asp:LinkButton ID="lbNextPage" runat="server" CommandArgument="Next" CommandName="Page" Visible="<%#((GridView)Container.NamingContainer).PageIndex!=((GridView)Container.NamingContainer).PageCount-1 %>">下一页</asp:LinkButton>
                                <asp:LinkButton ID="lbLastPage" runat="server" CommandArgument="Last" CommandName="Page" Visible="<%#((GridView)Container.NamingContainer).PageIndex!=((GridView)Container.NamingContainer).PageCount-1 %>">尾页</asp:LinkButton>
                                <asp:TextBox ID="txtNewPageIndex" runat="server" Text="<%#((GridView)Container.Parent.Parent).PageIndex+1 %>" Width="20px"></asp:TextBox>
                                <asp:LinkButton ID="btnGo" runat="server" CausesValidation="false" CommandArgument="go" CommandName="Page" Text="跳转" OnClick="btnGo_Click"></asp:LinkButton>
                            </td>
                        </tr>
                    </table>
</PagerTemplate>


处理跳转按钮的事件:

  protected void btnGo_Click(object sender, EventArgs e)
        {
            if (((LinkButton)sender).CommandArgument.ToLower().ToString().Equals("go"))
            {
                TextBox numBox = (TextBox)this.GridView1.BottomPagerRow.FindControl("txtNewPageIndex");
                int count = int.Parse(numBox.Text);
                GridView1.PageIndex = count - 1;
                DataBind();
            }
        }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

双叶红于二月花

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

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

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

打赏作者

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

抵扣说明:

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

余额充值