PageBarHelper分页显示类
一共有两个分页类,都可以使用(单独使用)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Common
{
public class PageBarHelper
{
/// <summary>
/// 计算数字页码条
/// </summary>
/// <param name="pageIndex">当前页码</param>
/// <param name="pageCount">总页数</param>
/// <returns></returns>
public static string GetPageBar(int pageIndex,int pageCount)
{
if (pageCount == 1)
{
return string.Empty;
}
//要求页面上要显示10个数字页码。
int start = pageIndex - 5;//计算起始位置
if (start < 1)
{
start = 1;
}
int end = start + 9;//计算终止位置.
if (end > pageCount)
{
end = pageCount;
start = end - 9<1?1:end-9;
}
StringBuilder sb = new StringBuilder();
if (pageIndex > 1)
{
sb.Append(string.Format("<a href='?pageIndex={0}' class='pageBarIndex'>上一页</a>", pageIndex - 1));
}
for (int i = start; i <= end; i++)
{
if (i == pageIndex)
{
sb.Append(i);
}
else
{
sb.Append(string.Format("<a href='?pageIndex={0}' class='pageBarIndex'>{0}</a>",i));
}
}
if (pageIndex < pageCount)
{
sb.Append(string.Format("<a href='?pageIndex={0}' class='pageBarIndex'>下一页</a>", pageIndex + 1));
}
return sb.ToString();
}
}
}
---------------------------------------------------------------------------分划线-------------------------------------------------------------------------------
using System;
using System.Text;
namespace WebDemo.Common
{
public class LaomaPager
{
/// <summary>
///
/// </summary>
/// <param name="pageSize">一页多少条</param>
/// <param name="currentPage">当前页</param>
/// <param name="totalCount">总条数</param>
/// <returns></returns>
public static string ShowPageNavigate(int pageSize, int currentPage, int totalCount)
{
string redirectTo = "";
pageSize = pageSize == 0 ? 3 : pageSize;
var totalPages = Math.Max((totalCount + pageSize - 1) / pageSize, 1); //总页数
var output = new StringBuilder();
if (totalPages > 1)
{
if (currentPage != 1)
{//处理首页连接
output.AppendFormat("<a class='pageLink' href='{0}?pageIndex=1&pageSize={1}'>首页</a> ", redirectTo, pageSize);
}
if (currentPage > 1)
{//处理上一页的连接
output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>上一页</a> ", redirectTo, currentPage - 1, pageSize);
}
else
{
// output.Append("<span class='pageLink'>上一页</span>");
}
output.Append(" ");
int currint = 5;
for (int i = 0; i <= 10; i++)
{//一共最多显示10个页码,前面5个,后面5个
if ((currentPage + i - currint) >= 1 && (currentPage + i - currint) <= totalPages)
{
if (currint == i)
{//当前页处理
//output.Append(string.Format("[{0}]", currentPage));
output.AppendFormat("<a class='cpb' href='{0}?pageIndex={1}&pageSize={2}'>{3}</a> ", redirectTo, currentPage, pageSize, currentPage);
}
else
{//一般页处理
output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>{3}</a> ", redirectTo, currentPage + i - currint, pageSize, currentPage + i - currint);
}
}
output.Append(" ");
}
if (currentPage < totalPages)
{//处理下一页的链接
output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>下一页</a> ", redirectTo, currentPage + 1, pageSize);
}
else
{
//output.Append("<span class='pageLink'>下一页</span>");
}
output.Append(" ");
if (currentPage != totalPages)
{
output.AppendFormat("<a class='pageLink' href='{0}?pageIndex={1}&pageSize={2}'>末页</a> ", redirectTo, totalPages, pageSize);
}
output.Append(" ");
}
output.AppendFormat("第{0}页 / 共{1}页", currentPage, totalPages);//这个统计加不加都行
return output.ToString();
}
}
}
PageBarHelper分页显示类的更多相关文章
- JSP分页显示实例(基于Bootstrap)
首先介绍一款简单利落的分页显示利器:bootstrap-paginator 效果截图: GitHub官方下载地址:https://github.com/lyonlai/bootstrap-pagina ...
- php中关于 left join 的分页显示
/* * 统计商机搜索总条数信息 * ftt * 2015-11-10 10:13:15 */ public function getBusinessCount($btype='',$buname=' ...
- 《ASP.NET1200例》<asp:DataList>分页显示图片
aspx页面代码 <asp:DataList ID="dlPhoto" runat="server" Height="137px" W ...
- SSh结合Easyui实现Datagrid的分页显示
近日学习Easyui,发现非常好用,界面很美观.将学习的心得在此写下,这篇博客写SSh结合Easyui实现Datagrid的分页显示,其他的例如添加.修改.删除.批量删除等功能将在后面的博客一一写来. ...
- java web 简单的分页显示
题外话:该分页显示是用 “表示层-控制层-DAO层-数据库”的设计思想实现的,有什么需要改进的地方大家提出来,共同学习进步. 思路:首先得在 DAO 对象中提供分页查询的方法,在控制层调用该方法查到指 ...
- ListView分页显示
出在:http://blog.csdn.net/tu_bingbing/article/details/13275107 当ListView要显示的数据过多时,为了更快的响应用户,这个 ...
- PHP常用之封装分页工具类
分页基本上是每个项目都会使用到的,所以呢,把它封装成一个工具类,以后直接调用就可以了(虽然TP框架的灰常强大,但是自己封一个也未尝不可.),这样既省时又省力还赚'工分'. 我封的这个分页工具类还比较完 ...
- 实例:SSh结合Easyui实现Datagrid的分页显示
近日学习Easyui,发现非常好用,界面很美观.将学习的心得在此写下,这篇博客写SSh结合Easyui实现Datagrid的分页显示,其他的例如添加.修改.删除.批量删除等功能将在后面的博客一一写来. ...
- 转:JSP 分页显示数据 (Oracle)
JSP 分页显示数据 (Oracle) 标签: Oracle分页JSP分页 2013-11-19 20:40 3598人阅读 评论(1) 收藏 举报 分类: Web(11) 版权声明:本文为博主原 ...
随机推荐
- Android开发 LiveData与MutableLiveData详解
前言 LiveData与ViewMode是经常搭配在一起使用的,但是为了不太混乱,我还是拆分开来说明,此篇博客只讲解 LiveData 与 MutableLiveData的概念与使用方式(但是会涉及到 ...
- leetcode-8-字符串转换整数(atoi)
题目描述: 方法一:正则 class Solution: def myAtoi(self, str: str) -> int: return max(min(int(*re.findall('^ ...
- APB简介
一.血缘 AMBA: Advanced Microcontroller Bus Architecture 高级处理器总线架构 AHB: Advanced High-performance Bus 高级 ...
- [JZOJ1901] 【2010集训队出题】光棱坦克
题目 题目大意 给你个平面上的一堆点,问序列\({p_i}\)的个数. 满足\(y_{p_{i-1}}>y_{p_i}\)并且\(x_{p_i}\)在\(x_{p_i-1}\)和\(x_{p_i ...
- thinkphp for标签
用法: 大理石平台厂家 <for start="开始值" end="结束值" comparison="" step="步进值 ...
- identifier of an instance of xx.entity was altered from xxKey@249e3cb2 to xxKey@74e8f4a3; nested exception is org.hibernate.HibernateException: identifier of an instance of xxentity was altered from错误
用entityManager保存数据时报错如下 identifier of an instance of xx.entity was altered from xxKey@249e3cb2 to xx ...
- php array_unshift,array_push追加数组元素
追加元素在数组前面:<?php $a=array("a"=>"Cat","b"=>"Dog"); ar ...
- awk 一些题目
1.1. 输出记录最多的IP [腾讯面试题]:一个文本类型的文件,里面每行存放一个登陆者的IP(某些行是重复的),写一个shell脚本输出登陆次数最多的用户. Ip_input.txt的内容假设如下: ...
- 1.2_springboot2.x中redis缓存&原理介绍
1.整合redis作为缓存 说明这里springboot版本2.19 Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件. 它支持多种类型的数据结构 ...
- React require(“history”).createBrowserHistory` instead of `require(“history/createBrowserHistory”)
看见bug惊讶,代码中并没有require("history/createBrowserHistory") //原有代码为 import createBrowserHistory ...