GridView自定义分页
来源:互联网 发布:csol解封软件 编辑:程序博客网 时间:2024/05/31 18:42
效果图:
前台代码:
<PagerTemplate > <br /> <asp:Label ID="lblPage" runat="server" Text='<%# "第" + (((GridView)Container.NamingContainer).PageIndex + 1) + "页/共" + (((GridView)Container.NamingContainer).PageCount) + "页" %> '></asp:Label> <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"></asp:TextBox> 页 <asp:Button ID="Button1" CommandName="go" runat="server" Text="Go" /> <br /> </PagerTemplate>
<asp:Label ID="lblPage" runat="server" Text='<%# "第" + (((GridView)Container.NamingContainer).PageIndex + 1)
这句代码是显示数据供有几页,当前在第几页。我们通过((GridView)Container.NamingContainer).PageIndex来获取当前页,通过((GridView)Container.NamingContainer).PageCount来获取总页数。
<asp:LinkButton ID="lbnFirst" runat="Server" Text="首页"
这一句代码实现跳转到列表的第一页,后台代码通过响应GridView.RowCommand 事件,根据CommandName="Page"和CommandArgument="First"来定位到分页列表的第一页。GridView中的任何一个按钮被点击都会触发RowCommand 事件,我们可以通过该事件来自定义处理程序。更多的时候建议使用GridView内置的属性。下表是MSDN上对GridView内置属性的一个简单说明。
在这个自定义分页中,上一页,下一页,尾页和首页都使用了内置属性。
这段代码是实现用户自己输入页码,然后点击Button跳转的的前台代码。为了使用RowCommand 事件,我们自定义了CommandName="go",当然你也可以在这里添加
#region private void GetGdlist() { //这里是连接数据库绑定GridView …… this.gdList.DataSource = ds; this.gdList.DataBind(); } #endregion #endregion #region Page Controls Events #region gdList_PageIndexChanging /// <summary> /// GridView分页按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void gdList_PageIndexChanging(object sender, GridViewPageEventArgs e) { try { gdList.PageIndex = e.NewPageIndex; GetGdlist(); TextBox tb = (TextBox)gdList.BottomPagerRow.FindControl("inPageNum"); tb.Text = (gdList.PageIndex + 1).ToString(); } catch { } } #endregion protected void gdList_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "go") { try { TextBox tb = (TextBox)gdList.BottomPagerRow.FindControl("inPageNum"); int num = Int32.Parse(tb.Text); GridViewPageEventArgs ea = new GridViewPageEventArgs(num - 1); gdList_PageIndexChanging(null, ea); } catch { } } }
这里主要有三个方法:
gdList_RowCommand方法,在这里是响应用户自己输入页码点击Button按钮的事件。首先获取用户输入的页码数,然后调用
- gridview实现自定义分页
- 自定义GridView分页模板
- GridView自定义分页
- GridView控件自定义分页
- GridView自定义分页导航
- GridView自定义分页
- GridView自定义分页导航
- GridView自定义分页导航
- GridView 自定义分页
- GridView自定义分页导航
- 自定义GridView分页模板
- GridView自定义分页
- [GridView控件]自定义分页
- gridview 自定义分页
- 自定义GridView分页模板
- gridview自定义分页
- GridView自定义分页
- 自定义GridView分页模板
- cocos2dx 3.x下cocosstudio使用
- swift 学习记录(类和结构体)
- 怎么用脚本选中一个物体,然后显示它的Inpsector面板
- [多线程之一]-NSThread银行取款问题
- LeetCode(76) Minimum Window Substring
- GridView自定义分页
- java 面试问题
- Android通知Notification入门小例子(一)
- online_judge_1126
- Rethinking the Inception Architecture for Computer Vision 笔记
- 实惠快速:海淘买鞋的经历:6PM +笨鸟海淘转运(单号: CN150815052072)
- jQ事件及操作大汇总
- 接口回调
- [Interview Summary] Load webpage from URL