采用Jquery无刷新分页插件jquery.pagination.js实现无刷新分页效果

1.插件参数列表

http://www.dtan.so

2.页面内容:

[c-sharp]view plaincopyprint? <%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%> <!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <htmlxmlns="http://www.w3.org/1999/xhtml"> <headrunat="server"> <title>Porschev----无刷新翻页</title> <mce:scriptsrc="Script/jquery-1.4.1.min.js"mce_src="Script/jquery-1.4.1.min.js"type="text/javascript"></mce:script> <mce:scriptsrc="Script/jquery.pagination.js"mce_src="Script/jquery.pagination.js"type="text/javascript"></mce:script> <mce:scriptsrc="Script/tablecloth.js"mce_src="Script/tablecloth.js"type="text/javascript"></mce:script> <linkhref="Style/tablecloth.css"mce_href="Style/tablecloth.css"rel="stylesheet"type="text/css"/> <linkhref="Style/pagination.css"mce_href="Style/pagination.css"rel="stylesheet"type="text/css"/> <mce:scripttype="text/javascript"><!-- varpageIndex=0;//页面索引初始值 varpageSize=10;//每页显示条数初始化,修改显示条数,修改这里即可 $(function(){ InitTable(0);//Load事件,初始化表格数据,页面索引为0(第一页) //分页,PageCount是总条目数,这是必选参数,其它参数都是可选 $("#Pagination").pagination(<%=pageCount%>,{ callback:PageCallback, prev_text:'上一页',//上一页按钮里text next_text:'下一页',//下一页按钮里text items_per_page:pageSize,//显示条数 num_display_entries:6,//连续分页主体部分分页条目数 current_page:pageIndex,//当前页索引 num_edge_entries:2//两侧首尾分页条目数 }); //翻页调用 functionPageCallback(index,jq){ InitTable(index); } //请求数据 functionInitTable(pageIndex){ $.ajax({ type:"POST", dataType:"text", url:'Handler/PagerHandler.ashx',//提交到一般处理程序请求数据 data:"pageIndex="+(pageIndex+1)+"&pageSize="+pageSize,//提交两个参数:pageIndex(页面索引),pageSize(显示条数) success:function(data){ $("#Resulttr:gt(0)").remove();//移除Id为Result的表格里的行,从第二行开始(这里根据页面布局不同页变) $("#Result").append(data);//将返回的数据追加到表格 } }); } }); //--></mce:script> </head> <body> <divalign="center"> <h2>Posrchev----无刷新分页</h2> </div> <divid="container"> <tableid="Result"cellspacing="0"cellpadding="0"> <tr> <th>编号</th> <th>名称</th> </tr> </table> <divid="Pagination"></div> </div> </body> </html>

3.页面后台内容:

[c-sharp]view plaincopyprint? usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Web; usingSystem.Web.UI; usingSystem.Web.UI.WebControls; publicpartialclass_Default:System.Web.UI.Page { publicstringpageCount=string.Empty;//总条目数 protectedvoidPage_Load(objectsender,EventArgse) { if(!IsPostBack) { pageCount=newPagerTestBLL.PersonManager().GetPersonCount().ToString(); } } }

4.Handler中的内容:

[c-sharp]view plaincopyprint? <%@WebHandlerLanguage="C#"Class="PagerHandler"%> usingSystem; usingSystem.Web; usingSystem.Collections.Generic; usingSystem.Text; publicclassPagerHandler:IHttpHandler{ publicvoidProce***equest(HttpContextcontext){ context.Response.ContentType="text/plain"; stringstr=string.Empty; //具体的页面数 intpageIndex; int.TryParse(context.Request["pageIndex"],outpageIndex); //页面显示条数 intsize=Convert.ToInt32(context.Request["pageSize"]); if(pageIndex==0) { pageIndex=1; } intcount; List<PagerTestModels.Person>list=newPagerTestBLL.PersonManager().GetAllPerson(size,pageIndex,"",outcount); StringBuildersb=newStringBuilder(); foreach(PagerTestModels.Personpinlist) { sb.Append("<tr><td>"); sb.Append(p.Id.ToString()); sb.Append("</td><td>"); sb.Append(p.Name); sb.Append("</td></tr>"); } str=sb.ToString(); context.Response.Write(str); } publicboolIsReusable{ get{ returnfalse; } } }

5.实现效果图: