C#一个显示分页页码类
2005-10-07 21:40
495 查看
在ASP.NET开发中,常用到显示分页页码程序,以下是本人写的一个类,还未完善,但已可使用,
在显示时当前页码会自动据中。并可自定义分类链接代码
using System;
namespace bookshopcn.Service
{
/// <summary>
/// Page 的摘要说明。
/// </summary>
public class Pager
{
public Pager(){}
protected static int _ButtonCount = 11;
protected static string _NextPage = "<a href={0}>下一页</a>";
protected static string _LinkUrl = "?page={0}";
protected static string _LastPage = "<a href={0}>上一页</a>";
/// <summary>
/// 下一页链接
/// </summary>
public static string NextPage
{
get{return _NextPage;}
set{_NextPage = value;}
}
/// <summary>
/// 上一页链接
/// </summary>
public static string LastPage
{
get{return _LastPage;}
set{_LastPage = value;}
}
/// <summary>
/// 设置时为格式
/// </summary>
public static string NextPageText
{
get{return _NextPage;}
set{_NextPage = value;}
}
/// <summary>
/// 显示按钮总数
/// </summary>
public static int BottonCount
{
get{return _ButtonCount;}
set{_ButtonCount = value;}
}
/// <summary>
/// 返回页面的分页信息
/// </summary>
/// <param name="_RecordCount">记录总数</param>
/// <param name="_PageSize">分页长度</param>
/// <param name="_PageIndex">当前页</param>
/// <returns></returns>
public static string PageInfo(int _RecordCount,int _PageSize,int _PageIndex,string link)
{
string Firstpage = string.Format("<a href="+link+">[首页]</a>","1");
string pageinfo = "共有{0}页 / 当前第{1}页 "+Firstpage;
string pagenext = " <a href="+link+"><b>{0}</b></a> ";
int PageCount = _RecordCount / _PageSize; // 页数合计
PageCount = PageCount <= 0?1:PageCount;
pageinfo = string.Format(pageinfo,PageCount.ToString(),_PageIndex.ToString());
string LastPage = string.Format("<a href="+link+">[末页]</a>",PageCount);
int n = _ButtonCount/2; //左右显示个数
int StartPage = _PageIndex - n;
int EndPage = _PageIndex + n;
_LastPage = string.Format(_LastPage,link); //上一页
_LastPage = _PageIndex-1>1?string.Format(_LastPage,(_PageIndex-1).ToString()):string.Format(_NextPage,"1");
_NextPage = string.Format(_NextPage,link); //下一页
_NextPage = _PageIndex+1<=PageCount?string.Format(_NextPage,_PageIndex.ToString()):string.Format(_NextPage,PageCount.ToString());
if(EndPage > PageCount )
{
StartPage = (_PageIndex - n) - (EndPage-PageCount);
EndPage = PageCount ;
}
if(StartPage < 1 )
{
EndPage = _ButtonCount;
StartPage = 1 ;
}
for(int i = StartPage;i<=EndPage;i++)
{
if(i != _PageIndex)
pageinfo += string.Format(pagenext,i);
else
pageinfo += " <b>" + i.ToString() + "</b> ";
}
pageinfo += LastPage;
return pageinfo;
}
}
}
在显示时当前页码会自动据中。并可自定义分类链接代码
using System;
namespace bookshopcn.Service
{
/// <summary>
/// Page 的摘要说明。
/// </summary>
public class Pager
{
public Pager(){}
protected static int _ButtonCount = 11;
protected static string _NextPage = "<a href={0}>下一页</a>";
protected static string _LinkUrl = "?page={0}";
protected static string _LastPage = "<a href={0}>上一页</a>";
/// <summary>
/// 下一页链接
/// </summary>
public static string NextPage
{
get{return _NextPage;}
set{_NextPage = value;}
}
/// <summary>
/// 上一页链接
/// </summary>
public static string LastPage
{
get{return _LastPage;}
set{_LastPage = value;}
}
/// <summary>
/// 设置时为格式
/// </summary>
public static string NextPageText
{
get{return _NextPage;}
set{_NextPage = value;}
}
/// <summary>
/// 显示按钮总数
/// </summary>
public static int BottonCount
{
get{return _ButtonCount;}
set{_ButtonCount = value;}
}
/// <summary>
/// 返回页面的分页信息
/// </summary>
/// <param name="_RecordCount">记录总数</param>
/// <param name="_PageSize">分页长度</param>
/// <param name="_PageIndex">当前页</param>
/// <returns></returns>
public static string PageInfo(int _RecordCount,int _PageSize,int _PageIndex,string link)
{
string Firstpage = string.Format("<a href="+link+">[首页]</a>","1");
string pageinfo = "共有{0}页 / 当前第{1}页 "+Firstpage;
string pagenext = " <a href="+link+"><b>{0}</b></a> ";
int PageCount = _RecordCount / _PageSize; // 页数合计
PageCount = PageCount <= 0?1:PageCount;
pageinfo = string.Format(pageinfo,PageCount.ToString(),_PageIndex.ToString());
string LastPage = string.Format("<a href="+link+">[末页]</a>",PageCount);
int n = _ButtonCount/2; //左右显示个数
int StartPage = _PageIndex - n;
int EndPage = _PageIndex + n;
_LastPage = string.Format(_LastPage,link); //上一页
_LastPage = _PageIndex-1>1?string.Format(_LastPage,(_PageIndex-1).ToString()):string.Format(_NextPage,"1");
_NextPage = string.Format(_NextPage,link); //下一页
_NextPage = _PageIndex+1<=PageCount?string.Format(_NextPage,_PageIndex.ToString()):string.Format(_NextPage,PageCount.ToString());
if(EndPage > PageCount )
{
StartPage = (_PageIndex - n) - (EndPage-PageCount);
EndPage = PageCount ;
}
if(StartPage < 1 )
{
EndPage = _ButtonCount;
StartPage = 1 ;
}
for(int i = StartPage;i<=EndPage;i++)
{
if(i != _PageIndex)
pageinfo += string.Format(pagenext,i);
else
pageinfo += " <b>" + i.ToString() + "</b> ";
}
pageinfo += LastPage;
return pageinfo;
}
}
}
相关文章推荐
- C#一个显示分页页码类
- C#一个显示分页页码类
- 一个带有页码的通用ASP.NET分页类,支持数据库分页(C#)
- C#在后台注册一个脚本,打开一个子窗口,显示在屏幕中间,关闭子窗体刷新子窗体代码
- 一个分页页码函数
- 一个多对多关系表的数据分页显示问题-sp_cursoropen 比较 临时表方式
- 这些年,早该懂的分页显示页码段
- JS实现简单分页,页码显示
- 用vbs模拟的一个asp的分页显示功能
- C#多线程delegate委托方式读取多文件到同一个文本框显示
- 一个相当独立的.通用分页控件c#源码三(downmoon收集)
- 利用MySQL的一个特性实现MySQL查询结果的分页显示
- 分页,删除操作后在该页码上显示
- Net通用分页类(存储过程分页版,可以选择页码的显示样式,且有中英选择)
- C#--第11周实验--任务3--设计一个窗体,窗体上有两个文本框,一个按钮,2个单选按钮--实现单击按钮后,根据单选按钮,将对应文本框中内容显示在标签。
- 一个显示页码用的helper。。。
- 一个c#.net存储过程版本的分页,支持百万数据分页
- C#开发WAP网站:数据分页显示
- ArcgisEngine+C#开发中,对一个图层进行过滤,并只显示符合条件的要素