惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
IT之家
IT之家
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
N
News | PayPal Newsroom
Cloudbric
Cloudbric
Webroot Blog
Webroot Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Simon Willison's Weblog
Simon Willison's Weblog
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
Vulnerabilities – Threatpost
Attack and Defense Labs
Attack and Defense Labs
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
S
Secure Thoughts
T
Tor Project blog
Latest news
Latest news
aimingoo的专栏
aimingoo的专栏
V2EX - 技术
V2EX - 技术
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Securelist
T
Tenable Blog
N
Netflix TechBlog - Medium
Google Online Security Blog
Google Online Security Blog
博客园 - Franky
T
Troy Hunt's Blog
量子位
大猫的无限游戏
大猫的无限游戏
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
MongoDB | Blog
MongoDB | Blog
H
Heimdal Security Blog
D
Docker
W
WeLiveSecurity
Stack Overflow Blog
Stack Overflow Blog
G
Google Developers Blog
博客园 - 叶小钗
腾讯CDC
The Hacker News
The Hacker News
WordPress大学
WordPress大学
人人都是产品经理
人人都是产品经理
Project Zero
Project Zero
Martin Fowler
Martin Fowler

博客园 - 夜帝

无进程木马 思路 [转] DateTime 日期操作 C#开发终端式短信的原理和方法 JavaScript实现功能全集 全国网络广播电台地址 转 C#调用Windows API函数 AJAX基础教程 C#实现窗体淡入淡出效果的几种方法 如何用C#语言构造蜘蛛程序 - 夜帝 - 博客园 C#冒泡排序算法 用Visual C#编写仿MSN Messager的滚动提示窗口 创建不规则窗体和控件 初识C#线程 JavaScript中文版(入门) C#日期函数所有样式大全 C#中的“装箱”(boxing)与“拆箱”(unboxing) .net 中随机数的产生 使用C#开发COM+组件 C#算法 -- (三)希尔排序
C#一个显示分页页码类
夜帝 · 2007-09-16 · via 博客园 - 夜帝

在显示时当前页码会自动据中。并可自定义分类链接代码

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;
 }
 }
}