异步分页

/// <summary>
/// 生成分页数列
/// </summary>
/// <param name="pageIndex">第几页</param>
/// <param name="pagenum">总页数</param>
/// <param name="total">设计总页数</param>
/// <returns>int数组</returns>
public static int[] fenye(int pageIndex, int pagenum,int total)
{
//当总页数小于分页数量时
if (pagenum < total)
{
int[] list = new int[pagenum+2];
//判断上一页
if (pageIndex <= 1)
{
list[0] = 1;
}
else
{
list[0] = pageIndex-1;
}
//判断上一页
if (pageIndex >= pagenum)
{
list[pagenum + 1] = pagenum;
}
else
{
list[pagenum + 1] = pageIndex + 1;
}
//给其他赋值
for (int i = 0; i < pagenum; i++)
{
list[i + 1] = i + 1;
}
return list;
}
else
{
int[] list=new int[total+2];
//判断上一页
if (pageIndex <= 1)
{
list[0] = 1;
}
else
{
list[0] = pageIndex - 1;
}
//判断上一页
if (pageIndex >= pagenum)
{
list[pagenum + 1] = pagenum;
}
else
{
list[pagenum + 1] = pageIndex + 1;
}
//给其他赋值
if (pageIndex > 1 && pageIndex <= (pagenum - total + 1))
{
for (int i = 0; i < total; i++)
{
list[i + 1] = pageIndex+i;
}
}
if (pageIndex <= 1)
{
for (int i = 0; i < total; i++)
{
list[i + 1] = i+1;
}
}
if (pageIndex > (pagenum - total + 1))
{
for (int i = 0; i < total; i++)
{
list[i + 1] = pagenum-total+1+i;
}
}
return list;
}

}
/// <summary>
/// 生成分页代码
/// </summary>
/// <param name="list">int数组</param>
/// <param name="url">url</param>
/// <param name="pageindex">第几页</param>
/// <returns>string</returns>
public static string FENYE(int[] list, string url, int pageindex)
{
StringBuilder code = new StringBuilder();
code.Append("<a class=‘sxy‘ style=‘width:81px;‘ href=‘").Append(url).Append("?pageindex=").Append(list[0]).AppendLine("‘>&lt; 上一页</a>");
for (int i = 0; i < (list.Length - 2); i++)
{
if ((i+1) == pageindex)
{
code.Append("<a class=‘hover‘ href=‘").Append(url).Append("?pageindex=").Append(list[i + 1]).Append("‘>").Append(list[i + 1]).AppendLine("</a>");
}
else
{
code.Append("<a href=‘").Append(url).Append("?pageindex=").Append(list[i + 1]).Append("‘>").Append(list[i + 1]).AppendLine("</a>");
}
}
code.Append("<a class=‘sxy‘ style=‘width:81px;‘ href=‘").Append(url).Append("?pageindex=").Append(list[list.Length - 1]).AppendLine("‘>&lt; 下一页</a>");
return code.ToString();
}
/// <summary>
/// 生成异步分页代码
/// </summary>
/// <param name="list">int数组</param>
/// <param name="pageindex">第几页</param>
/// <returns>string</returns>
public static string FENYE(int[] list, int pageindex,int pagenum)
{
StringBuilder code = new StringBuilder();
code.AppendLine("<a class=‘shouy hover‘ onclick=‘Page(1)‘ href=‘javascript:void(0)‘>首页</a>");
code.Append("<a class=‘sxy‘ style=‘width:81px;‘ href=‘").Append("javascript:void(0)").Append("‘ onclick=‘Page(").Append(list[0]).AppendLine(")‘>&lt; 上一页</a>");
for (int i = 0; i < (list.Length - 2); i++)
{
if ((i + 1) == pageindex)
{
code.Append("<a class=‘hover‘ href=‘").Append("javascript:void(0)").Append("‘ onclick=‘Page(").Append(list[i + 1]).Append(")‘>").Append(list[i + 1]).AppendLine("</a>");
}
else
{
code.Append("<a href=‘").Append("javascript:void(0)").Append("‘ onclick=‘Page(").Append(list[i + 1]).Append(")‘>").Append(list[i + 1]).AppendLine("</a>");
}
}
code.Append("<a class=‘sxy‘ style=‘width:81px;‘ href=‘").Append("javascript:void(0)").Append("‘ onclick=‘Page(").Append(list[list.Length - 1]).AppendLine(")‘>&lt; 下一页</a>");
code.AppendLine("<a class=‘shouy hover‘ onclick=‘Page(1)‘ href=‘javascript:void(0)‘>首页</a>");
code.AppendLine("<a class=‘shouy‘ href=‘javascript:void(0)‘ onclick=‘Page(").Append(pagenum).Append(")‘>末页</a>");
return code.ToString();
}

if (action == "GetData")
{
string key=context.Request.Params["li"];
string s = context.Request.Params["PageIndex"];
int pageindex = context.Request.Params["PageIndex"] == null ? 1 : Convert.ToInt16(context.Request.Params["PageIndex"]);
List<T_Log> list = new List<T_Log>();
T_LogDAL log=new T_LogDAL();
int i = log.GetAllNum();
i = (int)Math.Ceiling(i / (10 * 1.0));
if (key == "load")
{
list = log.GetData(pageindex);
}
else
{
list = log.GetData(key,pageindex);
}
int[] num = CommonHelper.fenye(pageindex,i,8);
string code = CommonHelper.FENYE(num,pageindex,i);
JavaScriptSerializer json = new JavaScriptSerializer();
var data = new {Page=code,Data=list };
string str = json.Serialize(data);
context.Response.Write(str);
return;
}

时间: 2024-08-09 19:52:32

异步分页的相关文章

Jquery异步分页插件

学校软件工程让写课程设计(其实就是自选语言做个项目),感觉都是重复的东西就没有很认真的去写内容,更加注意写一些之前没有用过的东西. 因为一直都使用TP框架来写PHP,TP又自带分页类,想到这里就想试试写一个异步分页,于是昨天用了4个小时思考带调试写来出来... 思路: 异步分页和同步分页最直观的一点就是切换数据页不用刷新页面,然后用Jquery动态的来创建一些html元素并给与相应的显示规则,结合后台请求来切换表格数据.切换表格数据不属于分页内容,因此这里只探讨分页空间本身. 实现: 接下来大致

thinphp原生异步分页

异步分页: $sql="............";   $result=$m->query($sql);   $count =count($result);   $page = new ExPage($count);   $result2=$m->query($sql.$page->get_limit);   $this->assign('page',$page->show());   $this->assign('list',$result2);

MVC 简单的AJAX异步分页+MYSQL

留资料,以后学习用 1.后台 public ActionResult textPage() { return View(); } [HttpPost] public ActionResult textPage(FormCollection collection) { //实例化对象 BLL.pc_dialog bll_pcdialog = new BLL.pc_dialog(); Model.pc_dialog model_pcdialog = new Model.pc_dialog(); //

ASP.NET MVC中使用MvcPager异步分页+在分页中复选框下一页上一页也保持选中

ASP.NET MVC 分页使用的是作者杨涛的MvcPager分页控件  地址:http://www.webdiyer.com/mvcpager/demos/ajaxpaging/ 这个分页控件在里面有很好的的案例,及注意事项 分页在我们的项目中是经常需要使用到的,普通分页体验是在是太差了,每一次点击下一步,会造成页面刷新,自己都看不过去了 ,O(∩_∩)O哈哈~ 所以这次我们要使用这个控件在做一个MvcPager的异步分页,分页的时候我们只刷新表格,而不是刷新页面 下面我们开始吧 一.分页 首

Lucene系列:(11)异步分页

使用到的jar包,分为4部分: (1)beanutils commons-beanutils-1.9.2.jar commons-collections-3.2.1.jar commons-logging-1.1.1.jar (2)gson gson-2.6.2.jar (3)IK Analyzer IKAnalyzer3.2.0Stable.jar (4)lucene lucene-analyzers-3.0.2.jar lucene-core-3.0.2.jar lucene-highlig

32、异步分页

既然做分页,首先要写好sql语句. 1.not in  --SQL2000 select top 10 * from huochetou where id not in (select top 10 id from huochetou) 2.row_number() --SQL2005 select * from ( select (row_number() over(order by id desc)) as num,* from huochetou) as t  where t.num be

Springmvc+Myabtis+Ajax实现异步分页emp+dept(全部查询及模糊查询)

1.在项目中创建如下目录 2.创建实体类Dept package com.entity; import java.io.Serializable; /** * 部门表 * @author Administrator * */ public class Dept implements Serializable{ /** * */ private static final long serialVersionUID = 1L; private Integer deptno; private Stri

mysql优化---订单查询优化(2):异步分页处理

订单分页查询: 老的代码是顺序执行查询数据和计算总记录数,但是如果条件复杂的话(比如关联子表)查询的时间要超过20s种 public static PagedList<Map<String, Object>> query(ITemplateService service, Identity tenantId, Identity userId, String entityName, Map<String, Object> params, String columns, T

MVC异步分页

如图: 1: 控制器代码 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 //         // GET: /AjaxUser/         shopEntities shop = new shopEntities();         public ActionResult Index()         {             return View();         }