分页控件AspNetPager学习笔记
1、AspNetPager简介
AspNetPager是一款开源、简单易用、可定制化等等各种优点的Web分页控件。
2、使用方法
1)下载AspNetPager.dll文件(http://www.webdiyer.com/aspnetpager/downloads/)
2)添加对该文件的引用
3)工具栏右键-选择项,把该dll控件添加进工具栏
4)把该控件拖进设计界面,设置控件的各种属性如下:
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" FirstPageText='首页' LastPageText='尾页'
PagingButtonSpacing="10px" ShowPageIndexBox="Always" CustomInfoHTML="共%RecordCount%条,第%CurrentPageIndex%页 /共%PageCount% 页"
NextPageText="下一页" PrevPageText="上一页" ShowCustomInfoSection="Left" SubmitButtonText="Go"
TextAfterPageIndexBox="页" TextBeforePageIndexBox="转到 " UrlPaging="True" CustomInfoSectionWidth="20%"
CustomInfoTextAlign="Center" OnPageChanged="AspNetPager1_PageChanged" PageSize="" CurrentPageButtonPosition="Center">
</webdiyer:AspNetPager>
属性的意思大概都看的明白,如果看不明白的就去http://www.webdiyer.com/aspnetpager/faq/ 自己研究。
如果不想显示“共X条,第X页/共X页”,可以不设置CustomInfoHTML属性
5)编写后台cs代码如下:
protected void Page_Load(object sender, EventArgs e)
{
BindGv(,AspNetPager1.PageSize);//绑定第一页数据
} public void BindGv(int pageIndex,int pageSize)
{
//连接数据库
string connStr = "Data source=.;Initial Catalog=EFText;Integrated Security=True";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
string sql = "select * from Texts";
SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
DataTable dt = new DataTable();
DataSet ds = new DataSet();
adapter.Fill(ds, (pageIndex - ) * pageSize,pageSize,"a");//获取该页数据
adapter.Fill(dt);
AspNetPager1.AlwaysShow = true;
AspNetPager1.RecordCount = dt.Rows.Count;//记录总数
AspNetPager1.CurrentPageButtonClass = "cpb";//当前选中页码
GridView1.DataSource = ds.Tables[];
GridView1.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
BindGv(AspNetPager1.CurrentPageIndex,AspNetPager1.PageSize);
}
注:这里获取到的数据源是分页后的,即代码中的DataSet,但不一定非要使用SqlDataAdapter,只要把要获取的分页数据查询出来即可,可以自己写分页sql语句,也可以写存储过程, 不会写可以去网上自动生成,地址:http://www.webdiyer.com/aspnetpager/spgenerator/。
这里的代码没有使用任何框架和工具类,真正项目中使用时最好把连接数据库和执行sql语句的代码写到工具类中
6)写完以上代码后分页功能就已经实现了,但是比较丑,因此还要再加一些样式,这里我整理了几个看起来还凑合的css代码:
使用方法:在AspnetPager控件外面套一个div,并设置该div的class属性为css名(pager)

.pager
{
width: 95%;
margin: 10px;
line-height: 20px;
display: block;
}
.pager span
{
border: 1px solid #CCCCCC;
margin: 0 5px;
padding: 1px 6px;
float: left;
}
.pager a
{
border: 1px solid #CCCCCC;
display: block;
overflow: hidden;
float: left;
margin: 0 5px;
padding: 1px 6px;
}
.pager a:hover
{
border: 1 solid red;
background-color: #993399;
color: #ffffff;
margin: 0 5px;
padding: 1px 6px;
}
注:使用上面这个css需要在后台把设置CurrentPageButtonClass 的那句代码注释掉。

.pager1
{
font: 11px Arial, Helvetica, sans-serif;
padding: 10px 20px 10px 0;
margin: 0px;
}
.pager1 a
{
padding: 1px 6px;
border: solid 1px #ddd;
background: #fff;
text-decoration: none;
margin-right: 2px;
}
.pager1 a:visited
{
padding: 1px 6px;
border: solid 1px #ddd;
background: #fff;
text-decoration: none;
}
.pager1 .cpb
{
padding: 1px 6px;
font-weight: bold;
font-size: 13px;
border: none;
color:#ffa501;
}
.pager1 a:hover
{
color: #fff;
background: #ffa501;
border-color: #ffa501;
text-decoration: none;
}

.pager2
{
color: #999;
}
.pager2 a, .pager2 .cpb
{
text-decoration: none;
float: left;
padding: 0 5px;
border: 1px solid #ddd;
background: #ffff;
margin: 0 2px;
font-size: 11px;
color: #000;
}
.pager2 a:hover
{
background-color: #E61636;
color: #fff;
border: 1px solid #E61636;
text-decoration: none;
}
.pager2 .cpb
{
font-weight: bold;
color: #fff;
background: #E61636;
border: 1px solid #E61636;
}

.pager3
{
font: 12px Arial, Helvetica, sans-serif;
padding: 10px 20px 10px 0;
margin: 0px;
}
.pager3 a
{
border: solid 1px #ccc;
color: #0063dc;
cursor: pointer;
text-decoration: none;
}
.pager3 a:visited
{
padding: 1px 6px;
border: solid 1px #ddd;
background: #fff;
text-decoration: none;
}
.pager3 .cpb
{
border: 1px solid #F50;
font-weight:;
color: #F50;
background-color: #ffeee5;
}
.pager3 a:hover
{
border: solid 1px #F50;
color: #f60;
text-decoration: none;
}
.pager3 a, .pager3 a:visited, .pager3 .cpb, .pager3 a:hover
{
float: left;
height: 16px;
line-height: 16px;
min-width: 10px;
_width: 10px;
margin-right: 5px;
text-align: center;
white-space: nowrap;
font-size: 12px;
font-family: Arial,SimSun;
padding: 0 3px;
}
3、后记
AspNetPager的功能还有很多,如逆向分页、Url重写、自定义按钮图片、Ajax分页等等,有兴趣的可以自己上网学习,地址:http://www.webdiyer.com/aspnetpager/
但AspNetPager只能在WebForm中使用,想在MVC中使用此控件需要学习另一个相似的控件MvcPager,地址:http://www.webdiyer.com/mvcpager/
分页控件AspNetPager学习笔记的更多相关文章
- 第三方分页控件aspnetPager出现问题解决方法
问题描述: 今天在打开以前的项目使用vs2013打开后并且生成解决方案的时候发现报错了.经过检查发现是由于第三方分页控件aspnetPager在页面上不能引用到了. 解决方法: 1. 首先将AspNe ...
- web分页控件AspNetPager的使用
首先要先引用AspNetPager.dll文件 然后在<html>上面添加下面代码: <%@ Register Assembly="AspNetPager" Na ...
- Repeater + 分页控件 AspNetPager 研究
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs ...
- 分页控件 AspNetPager的使用
1.引用AspNetPager.dll插件 1.下载AspNetPager.dll插件到bin文件夹中. 2.在“引用中添加引用”(不然报错:未能在全局命名空间中找到类型或命名名空间名称“Wuqi”) ...
- C# - 杨涛分页控件AspNetPager
http://www.webdiyer.com/downloads/ 前台 <%@ Page Language="C#" AutoEventWireup="true ...
- asp.net分页控件库
AspNetPager分页控件 AspNetPager分页控件解决了分页中的很多问题,直接采用该控件进行分页处理,会将繁琐的分页工作变得简单化,下面是我如何使用AspNetPager控件进行分页处理的 ...
- .net core 学习笔记(1)-分页控件的使用
最近有个小项目,用.net core开发练练手,碰到的第一个问题就是分页控件的问题,自己写太费时间,上网查了下,发现有人已经封装好了的,就拿过来用了,分页控件github:https://github ...
- AspNetPager分页控件配置
AspNetPager是asp.net中常用的分页控件,下载AspNetPager.dll,添加引用,在工具栏就可以看到AspNetPager控件: 拖过来之后,设置如下属性: <webdiye ...
- AspNetPager分页控件
AspNetPager分页控件解决了分页中的很多问题,直接采用该控件进行分页处理,会将繁琐的分页工作变得简单化,下面是我如何使用AspNetPager控件进行分页处理的详细代码:1.首先到www.we ...
随机推荐
- XML解析之SAX解析技术案例
Java代码: package com.xushouwei.xml; import java.io.File; import java.io.IOException; import java.text ...
- @dynamic 与 @synthesize
@synthesize是默认选项,表示为属性自动生成getter方法和setter方法 @dynamic 需要在实现文件里注明.例如 @dynamic name:表示用开发者手动动态实现getter和 ...
- zoom:1-hasLayout
在现代浏览器,如果子元素float,则父元素不会自动被撑开 #nofloatbox { border: 1px solid #FF0000; background: #CCC; width:200px ...
- Objective-C 关于静态方法与实例方法的转载
objective-c中非常重要的语法知识,在此归纳总结一下. 类方法,也称静态方法,指的是用static关键字修饰的方法.此方法属类本身的方法,不属于类的某一个实例(对象).类方法中不可直接使用实例 ...
- Apriori算法原理总结
Apriori算法是常用的用于挖掘出数据关联规则的算法,它用来找出数据值中频繁出现的数据集合,找出这些集合的模式有助于我们做一些决策.比如在常见的超市购物数据集,或者电商的网购数据集中,如果我们找到了 ...
- springmvc java.lang.NoSuchMethodError: com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z
在hibernate spring springMVC整合的时候出现下面的情况: WARNING: Exception encountered during context initializatio ...
- [源代码] SailingEase .NET Resources Tool (.NET 多语言资源编辑器)
我在2016年10月发过一篇博客,介绍了我写过的一个多语言资源文件编辑器,并且做为免费软件发布给了出来. 陆续收到了一些朋友的反馈,有朋友很热心提了很多建议和关心的话,还有朋友发红包过来,让我很感动. ...
- Condition源码分析
转:http://www.nbtarena.com/Html/soft/201308/2429.html Condition的概念 大体实现流程 I.初始化状态 II.await()*作 III.si ...
- C++ 头文件系列(map)
简介 该头文件包含两个概念相似的容器----map.multimap. 而这两个容器反映的概念就是 映射. 这两个容器 相同 的属性有: 关联性 映射 动态增长 键(Key)唯一性 这两个不相同的属性 ...
- 【G】开源的分布式部署解决方案(二) - 好项目是从烂项目基础上重构出来的
分析目前项目结构 眼前出现这么一坨坨的文件夹,相信很多人已经看不下去了.是的,首先就是要把它给做掉. 按照这个项目文件夹的命名意图,大概可以划分如下: 1.Business:业务代码 2.Data:数 ...