Repeater使用 AspNetPager分页控件 仿(网易、拍拍、迅雷)
来源:互联网 发布:淘宝主图视频pr 编辑:程序博客网 时间:2024/05/22 06:13
一、AspNetPager分页控件
分页是Web应用程序中最常用到的功能之一,在ASP.NET中,虽然自带了一个可以分页的DataGrid(asp.net 1.1)和GridView(asp.net 2.0)控件,但其分页功能并不尽如人意,如可定制性差、无法通过Url实现分页功能等,而且有时候我们需要对DataList和Repeater甚至自定义数据绑定控件进行分页,手工编写分页代码不但技术难度大、任务繁琐而且代码重用率极低,因此分页已成为许多ASP.NET程序员最头疼的问题之一。
AspNetPager针对ASP.NET分页控件的不足,提出了与众不同的解决asp.net中分页问题的方案,即将分页导航功能与数据显示功能完全独立开来,由用户自己控制数据的获取及显示方式,因此可以被灵活地应用于任何需要实现分页导航功能的地方,如为GridView、DataList以及Repeater等数据绑定控件实现分页、呈现自定义的分页数据以及制作图片浏览程序等,因为AspNetPager控件和数据是独立的,因此要分页的数据可以来自任何数据源,如SQL Server、Oracle、Access、mysql、DB2等数据库以及XML文件、内存数据或缓存中的数据、文件系统等等。
二、基本属性:
AlwaysShow:
默认情况下,当要分页的数据只有一页时,AspNetPager默认会自动危险期而不在页面上显示任何可见内容,将此属性值设为true时,即使总页数只有一页,AspNetPager也将显示分页导航元素。
FirstPageText:
获取或设置为第一页按钮显示的文本。
LastPageText:
获取或设置为最后一页按钮显示的文本。
NextPageText:
获取或设置为下一页按钮显示的文本。
PrevPageText:
获取或设置为上一页按钮显示的文本。
PageSize:
获取或设置每页显示的项数。(该值获取或设置数据呈现控件每次要显示数据表中的的数据的项数,AspNetPager根据该值和 RecordCount 来计算显示所有数据需要的总页数,即 PageCount的值。 )
CssClass:
应用于控件的css类名
CurrentPageButtonClass:
获取或设置AspNetPager分页控件当前页导航按钮的级联样式表 (CSS) 类。
PageIndexBoxType:
或者或设置页索引框的显示类型,可以是允许用户手工输入的文本框和只能选择的下拉框。
ShowBoxThreshold:
当 ShowPageIndexBox 设为Auto(默认)并且要分页的数据的总页数达到该值时会自动显示页索引输入文本框,默认值为30。该选项当 ShowPageIndexBox 设为Never或Always时没有任何作用。
三、风格样式:
===== 网易风格 =====
.anpager .cpb {background:#1F3A87 none repeat scroll 0 0;border:1px solid #CCCCCC;color:#FFFFFF;font-weight:bold;margin:5px 4px 0 0;padding:4px 5px 0;}
.anpager a {background:#FFFFFF none repeat scroll 0 0;border:1px solid #CCCCCC;color:#1F3A87;margin:5px 4px 0 0;padding:4px 5px 0;text-decoration:none}
.anpager a:hover{background:#1F3A87 none repeat scroll 0 0;border:1px solid #1F3A87;color:#FFFFFF;}
属性设置:CssClass="anpager" CurrentPageButtonClass="cpb"
===== 拍拍网风格 =====
.paginator { font: 11px Arial, Helvetica, sans-serif;padding:10px 20px 10px 0; margin: 0px;}
.paginator a {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;margin-right:2px}
.paginator a:visited {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;}
.paginator .cpb {padding: 1px 6px;font-weight: bold; font-size: 13px;border:none}
.paginator a:hover {color: #fff; background: #ffa501;border-color:#ffa501;text-decoration: none;}
属性设置:CssClass="paginator" CurrentPageButtonClass="cpb"
===== 迅雷风格 =====
.pages { color: #999; }
.pages a, .pages .cpb { text-decoration:none;float: left; padding: 0 5px; border: 1px solid #ddd;background: #ffff;margin:0 2px; font-size:11px; color:#000;}
.pages a:hover { background-color: #E61636; color:#fff;border:1px solid #E61636; text-decoration:none;}
.pages .cpb { font-weight: bold; color: #fff; background: #E61636; border:1px solid #E61636;}
属性设置:CssClass="pages" CurrentPageButtonClass="cpb"
四、如何调用:
index.aspx文件
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<%@ Register src="hand.ascx" tagname="hand" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="inc/css.css" rel="stylesheet" type="text/css" />
<style type="text/css">
/*网易风格*/
.anpager .cpb {background:#1F3A87 none repeat scroll 0 0;border:1px solid #CCCCCC;color:#FFFFFF;font-weight:bold;margin:5px 4px 0 0;padding:4px 5px 0;}
.anpager a {background:#FFFFFF none repeat scroll 0 0;border:1px solid #CCCCCC;color:#1F3A87;margin:5px 4px 0 0;padding:4px 5px 0;text-decoration:none}
.anpager a:hover{background:#1F3A87 none repeat scroll 0 0;border:1px solid #1F3A87;color:#FFFFFF;}
/*拍拍网风格*/
.paginator { font: 11px Arial, Helvetica, sans-serif;padding:10px 20px 10px 0; margin: 0px;}
.paginator a {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;margin-right:2px}
.paginator a:visited {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;}
.paginator .cpb {padding: 1px 6px;font-weight: bold; font-size: 13px;border:none}
.paginator a:hover {color: #fff; background: #ffa501;border-color:#ffa501;text-decoration: none;}
/*迅雷风格*/
.pages { color: #999 }
.pages a, .pages .cpb { text-decoration:none;float: left; padding: 0 5px; border: 1px solid #ddd;background: #ffff;margin:0 2px; font-size:11px; color:#000;}
.pages a:hover { background-color: #E61636; color:#fff;border:1px solid #E61636; text-decoration:none;}
.pages .cpb { font-weight: bold; color: #fff; background: #E61636; border:1px solid #E61636;}
.code{font-weight:bold;color:blue}
</style>
</head>
<body>
<form id="form1" runat="server">
<uc1:hand ID="hand1" runat="server" />
<div style="text-align:left; line-height:20px">
<asp:Repeater ID="SoftDown" runat="server">
<ItemTemplate>
<div style="border-bottom:1px solid #000000"><%#Eval("E_id")%> <%#Eval("Class")%><br><%#Eval("DownTitle")%><br><%#Eval("PageHome")%></div>
</ItemTemplate>
</asp:Repeater>
<div style="text-align:right; padding-top:10px">
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" pagesize="5" CssClass="anpager" onpagechanged="AspNetPager1_PageChanged"
FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页"
ShowMoreButtons="False" ShowPageIndexBox="Never">
</webdiyer:AspNetPager></div>
</div>
</form>
</body>
</html>
index.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using GHSqlConn;
using Wuqi.Webdiyer;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
SqlConnection conn = DB.getConnection();
conn.Open();
SqlCommand Count = new SqlCommand();
Count.Connection = conn;
Count.CommandText = "select count(*) from T_SoftDown1";
AspNetPager1.RecordCount = (int)Count.ExecuteScalar();
//Response.Write(AspNetPager1.RecordCount);
conn.Close();
BindData();
}
}
public void BindData()
{
SqlConnection conn = DB.getConnection();
string sql = "select * from T_SoftDown1 order by E_id desc";//这句在大型数据中应该用:select top查询语句
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "temptbl");
DataTable dt = ds.Tables["temptbl"];
SoftDown.DataSource=dt;
SoftDown.DataBind();
}
protected void AspNetPager1_PageChanged(object src, EventArgs e)
{
//AspNetPager1.CurrentPageIndex = e.NewPageIndex;
BindData();
}
}
- Repeater使用 AspNetPager分页控件 仿(网易、拍拍、迅雷)
- aspnetpager 分页控件 仿 淘宝 迅雷 拍拍 样式
- Repeater使用 AspNetPager分页控件
- Repeater 使用 AspNetPager分页
- Repeater采用AspNetPager控件分页
- Repeater数据控件与aspnetpager分页控件使用例子:
- .NET实现Repeater控件+AspNetPager控件分页
- .NET实现Repeater控件+AspNetPager控件分页
- ASP.NET Repeater以及分页控件AspNetPager
- AspNetPager分页控件使用
- 使用AspNetPager控件分页
- 使用AspNetPager控件分页
- AspNetPager分页示例[Repeater控件分页]
- asp.net下Repeater使用 AspNetPager分页控件 不用存储过程 完美实现
- AspNetPager分页控件的使用
- AspNetPager分页控件的使用
- AspnetPager分页控件的使用
- AspNetPager分页控件的使用
- 关于一个CS项目,jvm内存溢出问题的解决方案
- java Date型时间比较大小
- mybatis输出sql语句
- Devexpress_Lable Report 绑定数据
- EasyUI进度条 后台实时监控
- Repeater使用 AspNetPager分页控件 仿(网易、拍拍、迅雷)
- linux CentOS 6.5 中安装与配置JDK-7
- NGROK 内网穿透利器
- 字符串处理
- 做项目时,在jsp页面获得项目的相对路径
- hdu 2642(比较裸的二维树状数组)
- 如何使用js像html的table标签中添加一行
- Android: 一个两点触控的案例
- 策略模式的思考