GridView分页的实现
要在GridView中加入
//实现分页
AllowPaging="true"
//一页数据10行
PageSize="10"
// 分页时触发的事件 OnPageIndexChanging="gvwDesignationName_PageIndexChanging"
在服务器事件里


bingDesignatioonName(); }


这里我给出一个通用显示分页的模板(网上搜的,自己给出注释)
Code <PagerTemplate> 当前第: //((GridView)Container.NamingContainer)就是为了得到当前的控件 <asp:Label ID="LabelCurrentPage" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"></asp:Label> 页/共: //得到分页页面的总数 <asp:Label ID="LabelPageCount" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageCount %>"></asp:Label> 页 //如果该分页是首分页,那么该连接就不会显示了.同时对应了自带识别的命令参数CommandArgument <asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page" Visible='<%#((GridView)Container.NamingContainer).PageIndex != 0 %>'>首页</asp:LinkButton> <asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev" CommandName="Page" Visible='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>'>上一页</asp:LinkButton> //如果该分页是尾页,那么该连接就不会显示了 <asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page" Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>下一页</asp:LinkButton> <asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page" Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'>尾页</asp:LinkButton> 转到第 <asp:TextBox ID="txtNewPageIndex" runat="server" Width="20px" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>'/>页 //这里将CommandArgument即使点击该按钮e.newIndex 值为3 <asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-2" CommandName="Page" Text="GO"/> </PagerTemplate>
对应该事件中代码为
Code protectedvoid gvwDesignationName_PageIndexChanging(object sender, GridViewPageEventArgs e) { // 得到该控件 GridView theGrid = sender as GridView; int newPageIndex =; if (e.NewPageIndex==-) { //点击了Go按钮 TextBox txtNewPageIndex =null;
//GridView较DataGrid提供了更多的API,获取分页块可以使用BottomPagerRow 或者TopPagerRow,当然还增加了HeaderRow和FooterRow GridViewRow pagerRow = theGrid.BottomPagerRow; if (pagerRow !=null) { //得到text控件 txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox; } if ( txtNewPageIndex!=null) { //得到索引 newPageIndex =int.Parse(txtNewPageIndex.Text) -; } } else { //点击了其他的按钮 newPageIndex = e.NewPageIndex; } //防止新索引溢出 newPageIndex = newPageIndex <? : newPageIndex; newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - : newPageIndex; //得到新的值 theGrid.PageIndex = newPageIndex; //重新绑定 bingDesignatioonName(); }
GridView分页的实现的更多相关文章
- asp.net gridview 分页显示不出来的问题
使用gridview分页显示,在点击第二页的时候显示空白,无数据. 原因是页面刷新,绑定datatable未执行 解决方法: 1.将datatable设置为静态 2.在OnPageIndexChang ...
- Android GridView 分页加载数据
android UI 往右滑动,滑动到最后一页就自动加载数据并显示 如图: package cn.anycall.ju; import java.util.ArrayList; import java ...
- GridView 分页方法
要实现GrdView分页的功能. 操作如下: 1.更改GrdView控件的AllowPaging属性为true. 2.更改GrdView控件的PageSize属性为 任意数值(默认为10) 3.更改G ...
- GridView分页排序
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridviewPage.asp ...
- GridView分页功能的实现
当GridView中显示的记录很多的时候,可以通过GridView的分页功能来分页显示这些记录.如果GridView是直接绑定数据库,则很简单:将"启动分页"打勾即可. 如果是用代 ...
- GridView分页的实现 ASP.NET c#(转)特好用
要在GridView中加入 //实现分页 AllowPaging="true" //一页数据10行 PageSize="10" // 分页时触发的事件OnPag ...
- 自己写的一个ASP.NET服务器控件Repeater和GridView分页类
不墨迹,直接上代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; usin ...
- GridView分页操作
1.html <PagerStyle HorizontalAlign="Center" /> <PagerTemplate> 第: <asp:Labe ...
- gridview分页
protected void lnkbtnFrist_Click(object sender, EventArgs e) { //首页 ; this.ReadData(); } protected v ...
随机推荐
- WordPress Events Manager插件多个跨站脚本漏洞
漏洞名称: WordPress Events Manager插件多个跨站脚本漏洞 CNNVD编号: CNNVD-201310-196 发布时间: 2013-10-15 更新时间: 2013-10-15 ...
- x64 stack walking、调用约定、函数参数识别
k = <rsp> <rip> <frame_count>x64下manual stack walking与x86不同,x86一般情况下有ebp chain,x64 ...
- Ice_cream’s world III--2122
Ice_cream’s world III Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- jQuery dataTables 网格
对于服务器来说,可以通过请求参数来获得当前的操作信息. 类型 名称 说明 int iDisplayStart 显示的起始索引 int iDisplayLength 显示的行数 int iColumns ...
- hdu 单调队列
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4122 代码: #include<cstdio> #include<iostream& ...
- weblogic开发模式与生产模式介绍
weblogic开发模式与生产模式介绍 开发模式:该模式启用自动部署 生产模式:该模式关闭自动部署 weblogic server 三种部署方法:自动部署.控制台部署.命令部署 自动部署:当其处于启用 ...
- Web测试点 转
一.输入框 1.字符型输入框: (1)字符型输入框:英文全角.英文半角.数字.空或者空格.特殊字符"~!@#¥%--&*?[]{}"特别要注意单引号和&符号.禁止直 ...
- git push 报错
git push报错误: Git push error: RPC failed; result=56, HTTP code = 200 fatal: The remote end hung up un ...
- Linux的文件属性
在Linux中,文件的拥有者可以将文件的属性设置成三种属性,可读(r).可写(w)和可执行(x).文件又分为三个不同的用户级别,文件的拥有者(u),文件的所属组(g),其他用户(o). 第一个字符显示 ...
- (2/18)重学Standford_iOS7开发_Xcode_课程笔记
第二课: 1.惰性初始化 -(ObjectType *)example { f(!_example) example =[[ObjectType alloc] init]; return _examp ...