Webform gridView分页

Webform gridView分页分页详解 从工具栏中拖拽 Gridview 数据控件 1 设置数据 AllowPaging True 并自定义每页显示的数目 PageSize 10 同时设置页索引改变事件 OnPageIndexC GridView1 PageIndexCha protectedvoi PageIndexCha objects

 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>页   <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(); } }
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/198149.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月26日 下午3:41
下一篇 2026年3月26日 下午3:41


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号