使用GridView自带分页的代码
- 关于GridView分页页码的讨论
- 在GridView中实现分页的效果方法非常easy,仅仅须要在“GridView任务”对话框中进行设置就能够了。在“GridView任务”对话框中,选择“启用分页”命令,这样建立起简单的分页效果。
- 在使用“启用分页”命令的时候要注意两点。
- (1) 是否同意分页
- GridView的AllowPaging属性。AllowPaging:是否同意分页。假设AllowPaging=“true”就是同意分页。否则就是不同意使用分页。
- (2) 每页记录数
- GridView的PageSize属性。在GridView控件的属性中能够设置每页显示的数据记录的个数。默认情况下PageSize的值是10,也能够依据须要进行设置。
- 假设想要对分页编码进行设置的话,能够在HTML代码中为GridView控件加入分页导航条形式代码。也就是启用GridView的PagerSettings属性,在PagerSettings属性中能够设置依据须要设置Mode的值,来实现分页编码的显示效果。
- <PagerSettings
- Mode = "NextPreviousFirstLast"
- FirstPageText = "第一页"
- LastPageText = "末页">
- </PagerSettings>
- 注意:
- PagerSettings属性的Mode:Numeric,NextPrevious,NextPreviousFirstLast,NumericFirstLast。有这四种,能够依据不同须要进行不同的选择设置。
- 自己主动设置分页效果
- 如今想要在GridView控件上显演示样例如以下页码信息:总页数、当前页、首页、上一页、下一页、尾页。
- 创建总页数
- <asp:Label ID="Lab_PageCount" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageCount %>"></asp:Label>
- 创建但前页
- <asp:Label ID="Lab_CurrentPage" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"></asp:Label>
- 创建首页
- <asp:LinkButton ID="LBtn_FirstPage" runat="server" CommandArgument="First" CommandName="Page"
- Visible="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">首页</asp:LinkButton>
- 创建上一页
- <asp:LinkButton ID="LBtn_PreviousPage" runat="server" CommandArgument="Prev" CommandName="Page"
- Visible="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">上一页</asp:LinkButton>
- 创建下一页
- <asp:LinkButton ID="LBtn_NextPage" runat="server" CommandArgument="Next" CommandName="Page"
- Visible="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">下一页</asp:LinkButton>
- 创建尾页
- <asp:LinkButton ID="LBtn_LastPage" runat="server" CommandArgument="Last" CommandName="Page"
- Visible="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">尾页</asp:LinkButton>
- 相应后台代码
- public void GetDataSet()
- {
- string zhuangtmc;
- zhuangtmc = Convert.ToString(DropDownList1.Text);
- string sql;
- sql = "Select L.LunWBH,L.LunWBT,Z.ZhuangTMC,L.ZhuCYHM,B.BianJM,L.TouGRQ From T_LunWXX L ,T_LunWZhT Z,T_BianJPL B ";
- sql += "Where L.ZhuangTBH=Z.ZhuangTBH AND B.LunWBH=L.LunWBH AND";
- sql += " B.BianJM='" + zhucyhm + "'";
- if (zhuangtmc != "")
- {
- sql += " And Z.ZhuangTMC='" + zhuangtmc + "'";
- }
- sql += " Order By TouGRQ";
- CommonDB = new Common();
- GridView1.DataSource = CommonDB.DataSource(sql);
- GridView1.DataBind();
- //用lblCurrentIndex来显示当前页的页数。
- LabelCurrentPage.Text = "第 " + (GridView1.PageIndex + 1).ToString() + " 页";
- //用LblPageCount来显示当前数据的总页数。
- LabelPageCount.Text = "共 " + GridView1.PageCount.ToString() + " 页";
- //用LblrecordCount来显示数据的总条数。
- LabelRecordCount.Text = "总共 " + CommonDB.DataSets(sql).Tables[0].Rows.Count.ToString() + " 条";
- // 计算生成分页页码,分别为:"首 页" "上一页" "下一页" "尾 页"
- //点击首页设定的值为1。
- LinkButtonFirstPage.CommandName = "1";
- //点击‘上一页’
- LinkButtonPreviousPage.CommandName = (GridView1.PageIndex == 0 ? "1" : GridView1.PageIndex.ToString());
- //点击‘下一页’
- LinkButtonNextPage.CommandName = (GridView1.PageCount == 1 ? GridView1.PageCount.ToString() : (GridView1.PageIndex + 2).ToString());
- //点击‘尾页’
- LinkButtonLastPage.CommandName = GridView1.PageCount.ToString();
- }
使用GridView自带分页的代码的更多相关文章
- GridView总结一:GridView自带分页及与DropDownList结合使用
GridView自带的分页功能实现: 要实现GrdView分页的功能 操作如下: 1.更改GrdView控件的AllowPaging属性为true. 2.更改GrdView控件的PageSize属性为 ...
- GridView自带分页 1总页数 首页 下一页 上一页 尾页 X 页 go 实现方法 .
在前台GRIDVIEW中添加如下代码 <PagerTemplate> <table> <tr> <td style="text-align: rig ...
- GridView使用自带分页功能时分页方式及样式PagerStyle
// 转向地址:http://www.bubuko.com/infodetail-412562.html GridView分页,使用自带分页功能,类似下面样式: 在aspx页面中,GridView上的 ...
- php分页类代码带分页样式效果(转)
php分页类代码,有漂亮的分页样式风格 时间:2016-03-16 09:16:03来源:网络 导读:不错的php分页类代码,将类文件与分页样式嵌入,实现php查询结果的精美分页,对研究php分页原理 ...
- GridView总结二:GridView自带编辑删除更新
GridView自带编辑删除更新逻辑很简单:操作完,重新绑定.总结总结,防止忘记... 效果图: 前台代码: <%@ Page Language="C#" AutoEvent ...
- “MVC+Nhibernate+Jquery-EasyUI” 信息发布系统 第六篇(图片新闻的添加以及带分页的静态页的生成)
“MVC+Nhibernate+Jquery-EasyUI” 信息发布系统 第六篇(图片新闻的添加以及带分页的静态页的生成) 一.这篇文章主要是要实现:图片新闻的添加,无刷新图片的上传,以及添加新闻静 ...
- Spring统一返回Json工具类,带分页信息
前言: 项目做前后端分离时,我们会经常提供Json数据给前端,如果有一个统一的Json格式返回工具类,那么将大大提高开发效率和减低沟通成本. 此Json响应工具类,支持带分页信息,支持泛型,支持Htt ...
- 非常不错的一个JS分页效果代码
这里分享一个不错的js分页代码. 代码中cpage是页面计数,应为全局变量,可以随处调用它: totalpage是总页数. 与asp分页代码很类似,也是先取得记录总数,然后实现分页,基本的分页思路与原 ...
- django上课笔记2-视图CBV-ORM补充-Django的自带分页-Django的自定义分页
一.视图CBV 1.urls url(r'^login.html$', views.Login.as_view()), 2.views from django.views import View cl ...
随机推荐
- Cocos2d-X 2.2嵌入MFC的子窗口
1.在cocos2dx目录下创建基于对话框的MFC工程,对话框中间放一个Picture控件 2.添加cocos2dx的相关头文件包含路径.库包含路径和依赖项,可以参考其他cocos工程设置 3.选中P ...
- delphi xe5 android 开发数据访问server端(一)
第一篇我们破解并安装了xe5 第二篇我们搭建了开发环境 接下来我们开发一个三层的android程序 建立一个webservices stand-alone vcl application 作为手机访 ...
- bootstrap table 服务器分页
1.封装MODEL using System;using System.Collections.Generic;using System.Linq;using System.Text;using Sy ...
- QLGame 2d Engine SpriteBatch类创建
GitHub地址:https://github.com/wsgzxl/QLGame2dEngine 今天说五个问题: 1.前面说到的 颜色不对的问题,是因为FreeImage读取出来的数据格式与Ope ...
- [转贴] C++ 判断主机是否处于联网状态下
直接让本机访问一个网站,如果成功的话,就说明成功联网,没有访问成功,则说明没有联网!!! #include<iostream> #include <WINSOCK2.H> #p ...
- SEH and C++ Exceptions,自定义CSeException
Description of CSeException CSeException class is based on CException class provided by MFC. I overw ...
- Perl脚本学习经验(三)--Perl中ftp的使用
使用use Net::FTP;Demo: my $Server = '192.168.1.1'; my $User = 'admin'; my $Password = 'admin' ...
- Process.RedirectStandardInput
获取或设置一个值,该值指示应用程序的输入是否从 Process.StandardInput 流中读取. 命名空间:System.Diagnostics程序集:System(在 system.dll 中 ...
- When to use DataContract and DataMember attributes?
When to use DataContract and DataMember attributes? I am very confused about the DataContract attri ...
- [LeetCode#218] The Skyline Problem
Problem: A city's skyline is the outer contour of the silhouette formed by all the buildings in that ...