欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

一个简单的GridView分页

发布时间:2025/4/14 编程问答 41 豆豆
生活随笔 收集整理的这篇文章主要介绍了 一个简单的GridView分页 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

在GridView里面加上

<PagerTemplate>
 <asp:LinkButton ID="FirstPage" runat="server" CommandName="Page" CommandArgument="First" Enabled="<%#((GridView)Container.Parent.Parent).PageIndex!=0 %>">首页</asp:LinkButton>
         <asp:LinkButton ID="PreviewPage" runat="server" CommandArgument="Prev" CommandName="Page" Enabled="<%#((GridView)Container.Parent.Parent).PageIndex!=0 %>">上一页</asp:LinkButton>
          <asp:LinkButton ID="NextPage" runat="server" CommandName="Page" CommandArgument="Next" Enabled="<%#((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>">
下一页</asp:LinkButton>
          <asp:LinkButton ID="LastPage" runat="server" CommandName="Page" CommandArgument="Last" Enabled="<%#((GridView)Container.Parent.Parent).PageIndex!=((GridView)Container.Parent.Parent).PageCount-1 %>">尾页</asp:LinkButton>第<asp:Label ID="lblcurPage" 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>页
        <asp:TextBox ID="txtGo" runat="server" Width="30px" Text='<%#((GridView)Container.Parent.Parent).PageIndex+1 %>'></asp:TextBox>页
          <asp:Button ID="btnTurn" runat="server" Text="转到" OnClick="btnTurn_Click" />
</PagerTemplate>

编辑模板双击Button在后台代码:
    protected void btnTurn_Click(object sender, EventArgs e)
    {
        GrvInquires.PageIndex = int.Parse(((TextBox)GrvInquires.BottomPagerRow.FindControl("txtGo")).Text) - 1;
        MyDataBind();
    }

转载于:https://www.cnblogs.com/gjwolf/archive/2012/04/27/2473630.html

总结

以上是生活随笔为你收集整理的一个简单的GridView分页的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。