




已阅读5页,还剩28页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
精品文档 1欢迎下载 GridViewGridView 分页系列 精装版 分页系列 精装版 1 1 GridViewGridView 自带分页 自带分页 GridViewGridView 自带的分页 是假分页 他每次从数据库把数据全部查自带的分页 是假分页 他每次从数据库把数据全部查 询出之后 通过分页的算法 进行按每页数量进行分页 询出之后 通过分页的算法 进行按每页数量进行分页 分页的属性元素 分页功能的实现就是通过对这些属性元素的操作实现的 分页的属性元素 分页功能的实现就是通过对这些属性元素的操作实现的 this GvShow PageIndex 当前页的索引 this GvShow PageCount 总共的页数 this GvShow Rows Count 当前页签内的gridview的行数 this GvShow PageSize 每页的记录数 this GvShow PageIndex this GvShow rows count 1 行索引 设置普通的设置普通的 GridViewGridView 分页 属性分页 属性AllowPaging True PageSize 2 设置分页事件设置分页事件 onpageindexchanging GvShow PageIndexChanging 后台方法绑定 后台方法绑定 protectedprotected voidvoid GvShow PageIndexChanging objectGvShow PageIndexChanging object sender sender GridViewPageEventArgsGridViewPageEventArgs e e this GvShow PageIndexthis GvShow PageIndex e NewPageIndex e NewPageIndex BindView BindView 2 2 自定义样式的 自定义样式的 GridViewGridView 自带分页 自带分页 普通的普通的 GridViewGridView 自带的分页 不带样式 只是普通的自带的分页 不带样式 只是普通的 1 2 31 2 3 等 如果希望获取到具有其他等 如果希望获取到具有其他 分页样式就应该设置分页样式就应该设置属性 后台访问此属性的实例 后台访问此属性的实例 this GvShow PagerSettings FirstPageText 首页 精品文档 2欢迎下载 this GvShow PagerSettings LastPageText 尾页 this GvShow PagerSettings NextPageText 下一页 this GvShow PagerSettings PreviousPageText 上一页 this GvShow PagerSettings Mode PagerButtons NextPreviousFirstLast 通过通过 PagerStyle 属性可以设置属性可以设置 GRIDVIEWGRIDVIEW 分页的样式分页的样式 3 3 在 在分页模板中自定义分页的样式 虽然微软开辟了这个分页模板中自定义分页的样式 虽然微软开辟了这个 模板提供给用户类似于自定义分页的功能 但这个功能完全还是基于微软的模板提供给用户类似于自定义分页的功能 但这个功能完全还是基于微软的 GridViewGridView 自带自带 的分页进行的 的分页进行的 属性的 Visable 的属性必须是 true AllowPaging true 与 PageSize 3 属性页都要进行相关的有效设置才可以 这种情况下的分页可以不使用属性页都要进行相关的有效设置才可以 这种情况下的分页可以不使用 onpageindexchanging GvShow PageIndexChanging 微软自带的分页事件 开发自己独立的分页微软自带的分页事件 开发自己独立的分页 事件与方法即可事件与方法即可 范例 范例 前台代码 前台代码 精品文档 3欢迎下载 asp Label ID lblRegionName runat server Text asp Label ID lblCityName runat server Text 精品文档 4欢迎下载 asp Label ID lblUserName runat server Text 首页 上一页 下一页 尾页 页次 0 0页 共0条记录 0条记录 页 后台代码 namespace GridViewDemo GridView分页系列 public partial class GridView自定义分页02 System Web UI Page protected void Page Load object sender EventArgs e if IsPostBack BindView InitButtons 精品文档 6欢迎下载 private void BindView DataTable dt UserDemoAccess GetUserSouce ViewState RowCounts dt Rows Count ToString this GvShow DataSource dt this GvShow DataBind protected void GvShow PageIndexChanging object sender GridViewPageEventArgs e this GvShow PageIndex e NewPageIndex BindView InitButtons protected void GvShow RowDataBound object sender GridViewRowEventArgs e if e Row RowType DataControlRowType DataRow e Row Attributes Add onmouseover this setAttribute BKC this style backgroundColor this style cursor default this style backgroundColor ffff99 e Row Attributes Add onmouseout this style backgroundColor this getAttribute BKC 精品文档 7欢迎下载 if e Row RowType DataControlRowType Pager GridViewRow gr e Row 页次 第几页 Label txtNowPage gr FindControl txtNowPage as Label 总页数 Label txtAllPage gr FindControl txtAllPage as Label 总记录数 Label txtTotal gr FindControl txtTotal as Label 条记录 页 Label txtNowRed gr FindControl txtNowRed as Label txtNowPage Text this GvShow PageIndex 1 ToString txtAllPage Text this GvShow PageCount ToString txtTotal Text ViewState RowCounts ToString txtNowRed Text this GvShow PageSize ToString 精品文档 8欢迎下载 protected void cmdCheck CheckedChanged object sender EventArgs e CheckBox cmdCheck this GvShow BottomPagerRow FindControl cmdCheck as CheckBox if cmdCheck Checked this GvShow PagerSettings Mode PagerButtons Numeric protected void GvShow RowCommand object sender GridViewCommandEventArgs e 控制页签 switch e CommandName case begin this GvShow PageIndex 0 break case before if this GvShow PageIndex 0 this GvShow PageIndex 1 精品文档 9欢迎下载 break case after if this GvShow PageIndex 1 cmdbegin Enabled true cmdbefore Enabled true cmdafter Enabled true cmdend Enabled true if this GvShow PageIndex 0 cmdbegin Enabled false cmdbefore Enabled false else if this GvShow PageIndex this GvShow PageCount 1 cmdafter Enabled false cmdend Enabled false 精品文档 12欢迎下载 此外还可以不利用此外还可以不利用GridViewGridView自带的分页模板标记自带的分页模板标记可以在可以在 GridViewGridView的外部构造一个的外部构造一个talbetalbe与与gridviewgridview对应 这样更加灵活 也应用于对应 这样更加灵活 也应用于divdiv中的中的 GridViewGridView 前台代码 前台代码 首页 上一页 下一页 尾页 页次 0 0页 共0条记录 0条记录 页 这俩种方式的区别在于 适用内部的分页模板标记 在触发事件后 不用重新绑定这俩种方式的区别在于 适用内部的分页模板标记 在触发事件后 不用重新绑定 GridViewGridView 这个是由 这个是由 GridViewGridView 内部的分页机制自动完成的 而采用外部构造的方式 在执行完之后 必须重新绑定内部的分页机制自动完成的 而采用外部构造的方式 在执行完之后 必须重新绑定 gridviewgridview 因为这个时候的 因为这个时候的 pageIndexpageIndex 等信息已经变化 需要重新进行绑定 等信息已经变化 需要重新进行绑定 后台代码 后台代码 protected void PagerButton Command object sender System Web UI WebControls CommandEventArgs e switch e CommandName case begin this GvShow PageIndex 0 break case before if this GvShow PageIndex 0 this GvShow PageIndex 1 break case after if this GvShow PageIndex this GvShow PageCount 1 this GvShow PageIndex 1 精品文档 14欢迎下载 break case end this GvShow PageIndex this GvShow PageCount 1 break 在设置完页签后 将数据源重新绑定到GridView中 BindView InitButtons 一个很好样式的假分页 功能齐全 一个很好样式的假分页 功能齐全 前台页面前台页面 精品文档 15欢迎下载 asp Label ID lblRegionName runat server Text asp Label ID lblCityName runat server Text 精品文档 16欢迎下载 asp Label ID lblUserName runat server Text 首页 上一页 下一页 尾页 精品文档 17欢迎下载 页次 0 0页 共0条记录 0条记录 页 精品文档 18欢迎下载 后台页面 namespace GridViewDemo GridView分页系列 public partial class GridView自定义分页04 System Web UI Page protected void Page Load object sender EventArgs e if IsPostBack BindView InitButtons InitDrp private void BindView DataTable dt UserDemoAccess GetUserSouce ViewState PageCount dt Rows Count ToString this GvShow DataSource dt this GvShow DataBind protected void GvShow RowDataBound object sender GridViewRowEventArgs e 精品文档 19欢迎下载 if e Row RowType DataControlRowType DataRow e Row Attributes Add onmouseover this setAttribute BKC this style backgroundColor this style cursor default this style backgroundColor ffff99 e Row Attributes Add onmouseout this style backgroundColor this getAttribute BKC protected void PagerButton Command object sender System Web UI WebControls CommandEventArgs e switch e CommandName case begin this GvShow PageIndex 0 break case before if this GvShow PageIndex 0 this GvShow PageIndex 1 精品文档 20欢迎下载 break case after if this GvShow PageIndex 1 this cmdbegin Enabled true this cmdbefore Enabled true this cmdafter Enabled true this cmdend Enabled true if this GvShow PageIndex 0 this cmdbegin Enabled false this cmdbefore Enabled false else if this GvShow PageIndex this GvShow PageCount 1 this cmdafter Enabled false this cmdend Enabled false 精品文档 22欢迎下载 protected void lbtnTurnNewPage Click object sender EventArgs e try int pageIndexNumber Convert ToInt32 this txtTurn Text Trim if pageIndexNumber this GvShow PageCount Response Write 越界 return else if pageIndexNumber 0 Response Write 负数不灵 return this GvShow PageIndex pageIndexNumber 1 BindView InitButtons catch Response Write 请输入数字 return 精品文档 23欢迎下载 region 下拉列表分页跳转 protected void drpPageNumbers SelectedIndexChanged object sender EventArgs e DropDownList drpPageNumbers DropDownList sender 改变GridView的页签 this GvShow PageIndex Convert ToInt32 ControlDrp 页签改变后 重新绑定 BindView InitButtons private void InitDrp this drpPageNumbers Items Clear for int i 0 i this GvShow PageCount i this drpPageNumbers Items Add new ListItem i 1 ToString i ToString private String ControlDrp 精品文档 24欢迎下载 set this drpPageNumbers SelectedValue value get return this drpPageNumbers SelectedValue endregion 一个利用一个利用 模板实现的假分页实例 可以在绑定的时模板实现的假分页实例 可以在绑定的时 候加入候加入 dropdownlistdropdownlist 的页面选择 的页面选择 前台页面 asp Label ID lblRegionName runat server Text asp Label ID lblCityName runat server Text 精品文档 26欢迎下载 asp Label ID lblUserName runat server Text 第 asp Label ID lblPageIndex runat server Text 页 共 asp Label ID lblPageCount runat server Text 页 asp LinkButton ID btnFirst runat server CausesValidation False CommandArgument First CommandName Page Enabled Text 首页 asp LinkButton ID btnPrev runat server CausesValidation False CommandArgument Prev CommandName Page Enabled Text 上一页 asp LinkButton ID btnNext runat server 精品文档 27欢迎下载 CausesValidation False CommandArgument Next CommandName Page Enabled Text 下一页 asp LinkButton ID btnLast runat server CausesValidation False CommandArgument Last CommandName Page Enabled Text 尾页 asp TextBox ID txtNewPageIndex runat server Text Width 20px namespace GridViewDemo GridView分页系列 public partial class GridView自定义分页05 System Web UI Page 精品文档 28欢迎下载 protected void Page Load object sender EventArgs e if IsPostBack BindView private void BindView DataTable dt UserDemoAccess GetUserSouce this GvShow DataSource dt this GvShow DataBind protected void GvShow RowDataBound object sender GridViewRowEventArgs e if e Row RowType DataControlRowType DataRow e Row Attributes Add onmouseover this setAttribute BKC this style backgroundColor this style cursor default this style backgroundColor ffff99 e Row Attributes Add onmouseout 精品文档 29欢迎下载 this style backgroundColor this getAttribute BKC protected void GvShow PageIndexChanging object sender GridViewPageEventArgs e GridViewRow gr this GvShow BottomPagerRow TextBox txtNewPageIndex gr FindControl txtNewPageIndex as TextBox string content CheckPageIndex if content string Empty Show this content 如果发现异常 则重新将文本框中的值 置换成当前页签的 txtNewPageIndex Text this GvShow PageIndex 1 ToString return NewPageIndex 本页跳转点击go的时候 为 2 增加一个处理 微软自带分页中 选中页 签当前页无法再点击 此时的e NewPageIndex默认为 2 else if e NewPageIndex 0 int pageIndexTemp Convert ToInt32 txtNewPageIndex Text 1 精品文档 30欢迎下载 this GvShow PageIndex pageIndexTemp BindView return this GvShow P
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 辽宁省大连市高中数学 第二章 圆锥曲线与方程 2.4 抛物线专项过定点问题说课稿 新人教B版选修2-1
- 徐州市规划课题申报书
- 教改课题立项申报书陕西
- 6.4 密度的应用 说课稿 2024-2025学年人教版八年级上册物理
- 劳动保障事务服务协议书5篇
- 2025-2030中国零信任网络安全架构在政企领域渗透率
- 慢性骨髓炎护理措施
- 2025-2030中国重点城市青年公寓租金定价模型与收益预测
- 2025-2030中国跨境电商物流网络优化与效率提升战略报告
- 2025-2030中国联合办公与居住融合模式可行性分析报告
- 《数字图像处理基础》课件
- 无取向硅钢热轧板翘皮缺陷成因及控制措施研究
- 煤矿机电安全事故培训课件
- 普外科进修汇报课件
- 《普通话宣传周》中小学推广普通话主题班会模板
- 2025年中国电信集团招聘考试试题及答案全收录
- 浙江省G12名校协作体2025学年第一学期9月高三上学期开学联考数学试卷
- (9月3日)铭记历史珍爱和平-纪念中国人民抗日战争暨世界反法西斯战争胜利80周年爱国主义主题教育班会课件
- 2025广东汕尾市海丰县纪委监委招聘政府聘员6人笔试模拟试题及答案解析
- 5.1 文明有礼(教学课件) 统编版道德与法治 八年级上册
- 私域流量运营策略及五大关键原则
评论
0/150
提交评论