using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace JPJC.Controllers
{
///
/// 分页类
///
/// 集合
public class Page : List
{
///
/// 索引页
///
public int PageIndex { get; set; }
///
/// 每页显示几条记录
///
public int PageSize { get; set; }
///
/// 一共几页
///
public int PageCount { get; set; }
///
/// 一共多少条记录
///
public int AllCount { get; set; }
///
/// 判断上一页
///
public bool HasPrevious
{
get
{
return PageIndex < PageCount - 1;
}
}
///
/// 判断下一页
///
public bool HasNext
{
get
{
return PageIndex > 0;
}
}
///
/// 翻页函数
///
///
IQueryable 数据
///
索引页
///
每页多少条
public Page(IQueryable source, int pageindex, int pagesize)
{
this.AllCount = source.Count();
this.PageIndex = pageindex;
this.PageSize = pagesize;
//总记录数与每页最大记录数求余
if (this.AllCount % this.PageSize == 0)
this.PageCount = Convert.ToInt32(this.AllCount / this.PageSize);
else
this.PageCount = Convert.ToInt32(this.AllCount / this.PageSize + 1);
if (this.PageIndex > this.PageCount) this.PageIndex = this.PageCount;
if (this.PageIndex < 1) this.PageIndex = 1;
var list = source.Skip(this.PageSize * (this.PageIndex - 1)).Take(this.PageSize);
this.AddRange(list);
}
}
}
这是分页类
使用方法
var Query = from t in context.DB_Users
select t;
Query = Query.OrderByDescending(p => p.UserID);
var list = new Page(Query, Page, PageSize);
翻页类
///
/// 显示分页信息
///
///
每页多少条
///
当前页
///
总页数
///
总计路数
///
记录单位
///
记录名称
///
翻页函数javascirpt
///
是否显示跳转按钮
///
public static string ShowPages(int PageSize, int PageIndex, int PageCount, int AllCount, string Unit, string ItemName, bool JumpPageButton)
{
string tempstr = "";
int jump = PageIndex + 1;
tempstr += "
共
" + AllCount + " " + Unit + ItemName + " ";
tempstr += " " + PageSize + "条/页 ";
tempstr += " 页次: " + PageIndex + "/" + PageCount + "页 ";
if (PageIndex < 2)
{
tempstr += " 首页 上一页 ";
}
else
{
tempstr += " 首页 ";
tempstr += " 上一页 ";
}
if (PageIndex >= PageCount)
{
tempstr += " 下一页 尾页";
jump = PageCount;
}
else
{
tempstr += " 下一页 ";
tempstr += " 尾页 ";
}
tempstr += " ";
if (JumpPageButton)
{
tempstr += " ";
tempstr += " 跳转";
if (PageCount == 1)
{
tempstr += "
}
else
{
tempstr += "
}
}
tempstr += "
tempstr += " " + PageSize + "条/页 ";
tempstr += " 页次: " + PageIndex + "/" + PageCount + "页 ";
if (PageIndex < 2)
{
tempstr += " 首页 上一页 ";
}
else
{
tempstr += " 首页 ";
tempstr += " 上一页 ";
}
if (PageIndex >= PageCount)
{
tempstr += " 下一页 尾页";
jump = PageCount;
}
else
{
tempstr += " 下一页 ";
tempstr += " 尾页 ";
}
tempstr += " ";
if (JumpPageButton)
{
tempstr += " ";
tempstr += " 跳转";
if (PageCount == 1)
{
tempstr += "
}
else
{
tempstr += "
}
}
tempstr += "
";
return tempstr;
}
使用方法
ShowPages(PageSize, Page, list.PageCount, list.AllCount, "个", "用户", true)