<script src="../Js/jQuery/jquery-1.8.2.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $("#pages").val(Math.ceil(50 / 10)); }); //翻页 function changePage(ctype) { switch (ctype) { case ‘first‘: $("#page").val(1); break; case ‘prev‘: if ($("#page").val() > 1) { var num = parseInt($("#page").val()) - 1; $("#page").val(num); } break; case ‘next‘: if ($("#page").val() < $("#pages").val()) { var num = parseInt($("#page").val()) + 1; $("#page").val(num); } break; case ‘last‘: $("#page").val($("#pages").val()); break; } // if ($("#newp").val() == $("#page").val()) // return false; populate(); } //获取数据 function populate() { if ($("#page").val() > $("#pages").val()) $("#page").val($("#pages").val()); var param = [ { name: ‘page‘, value: $("#page").val() } , { name: ‘rp‘, value: 10 } , { name: ‘sortname‘, value: "" } , { name: ‘sortorder‘, value: "" } , { name: ‘query‘, value: "" } , { name: ‘qtype‘, value: "" } , { name: ‘primaryKey‘, value: "" } ]; $.ajax({ type: "POST", url: "HandlerPager.ashx?Action=Pagers", async: true, data: param, dataType: "json", success: function(data) { $("#spanPageIndex").html(data); }, error: function(data) { try { } catch (e) { } } }); } </script>
<div> <input type="hidden" value="1" id="page" /><!--当前页--> <input type="hidden" value="1"id="pages" /><!--总页数--> <span id="first" onclick="changePage(this.id)">首页</span> <span id="prev" onclick="changePage(this.id)">上一页</span> <span id="spanPageIndex" >1</span> <span id="next" onclick="changePage(this.id)">下一页</span> <span id="last" onclick="changePage(this.id)">尾页</span> </div>
public class HandlerPager : IHttpHandler { private string requestParam = string.Empty;//HttpHandler用于异步调用提交的服务器类 public void ProcessRequest(HttpContext context) { requestParam = context.Request.QueryString["Action"]; switch (requestParam) { case "Pagers": //? Pagers(context); break; } } void Pagers(HttpContext context) { string result = string.Empty; Model_Wzsjfycs parm = FlexiGridParm.GetFlexiGridParam(context); result = parm.PageIndex.ToString(); context.Response.ContentType = "text/plain"; context.Response.Write(result); } public bool IsReusable { get { return false; } } }
/// <summary> /// 分页请求参数类 可有可无,为了方便获取数据 /// </summary> public class Model_Wzsjfycs { /// <summary> /// 当前页码 /// </summary> public int PageIndex; /// <summary> /// /// </summary> public int PageSize; /// <summary> /// 主键 /// </summary> public string PrimaryKey; /// <summary> /// 排序字段(多个字段用‘,‘号分开) /// </summary> public string OrderFields; /// <summary> /// 排序方式(asc 、desc) /// </summary> public string Order; /// <summary> /// 查询字段 /// </summary> public string FilterFields; /// <summary> /// 查询内容 /// </summary> public string FilterContents; }
public class FlexiGridParm { /// <summary> /// 从HTTP中提取请求并封装FlexiGridParm类 用于解析 HttpContent请求上下文对象(页面发送请求的数据 以及 请求后返回的数据 ); /// </summary> /// <param name="context">HttpContext</param> /// <returns>Model_PagingParm</returns> public static Model_Wzsjfycs GetFlexiGridParam(HttpContext context) { string pageIndex = context.Request["page"], pageSize = context.Request["rp"], primaryKey = context.Request["primaryKey"], orderFields = context.Request["sortname"], order = context.Request["sortorder"], filterFields = context.Request["qtype"], filterContents = context.Request["query"]; Model_Wzsjfycs parm = new Model_Wzsjfycs(); //当前页码 if (!string.IsNullOrEmpty(pageIndex)) parm.PageIndex = int.Parse(pageIndex); else parm.PageIndex = 0; //一页显示条数 if (!string.IsNullOrEmpty(pageSize)) parm.PageSize = int.Parse(pageSize); else parm.PageSize = 0; //主键 if (!string.IsNullOrEmpty(primaryKey)) parm.PrimaryKey = primaryKey; else parm.PrimaryKey = string.Empty; //排序 if (!string.IsNullOrEmpty(orderFields)) parm.OrderFields = orderFields.Trim(); else parm.OrderFields = string.Empty; //排序字段 if (!string.IsNullOrEmpty(order) && order.ToLower() == "desc") parm.Order = "desc"; else parm.Order = "asc"; //查询字段 if (!string.IsNullOrEmpty(filterFields) && filterContents != null) { parm.FilterFields = filterFields; parm.FilterContents = context.Server.UrlDecode(filterContents); } else parm.FilterFields = parm.FilterContents = string.Empty; return parm; } /// <summary> /// 获取FlexiGridParm 对象 /// </summary> /// <param name="pageIndex">当前页码</param> /// <param name="pageSize">一页显示条数</param> /// <param name="primaryKey">主键</param> /// <param name="orderFields">排序字段(多个用‘,‘号隔开)</param> /// <param name="order">排序方式(asc、desc)</param> /// <param name="filterFields">查询字段</param> /// <param name="filterContents">查询内容</param> /// <returns>Model_PagingParm</returns> public static Model_Wzsjfycs GetFlexiGridParam(int pageIndex, int pageSize, string primaryKey, string orderFields, string order, string filterFields, string filterContents) { Model_Wzsjfycs parm = new Model_Wzsjfycs(); parm.PageIndex = pageIndex; parm.PageSize = pageSize; parm.PrimaryKey = primaryKey; parm.OrderFields = orderFields; parm.Order = order; parm.FilterFields = filterFields; parm.FilterContents = filterContents; return parm; } }
时间: 2024-10-28 02:58:15