本文转自:http://do-web.com/jpaging/usage

How does it work?

1. In order to implement the plugin, you need to insert inside the head tag of your document the last jQuery file, jquery.jpaging.0.1.min.js and jpaging.css.

  1. <scripttype="text/javascript"language="javascript"src="js/jquery-1.5.2.min.js"></script>
  2. <scripttype="text/javascript"language="javascript"src="js/jquery.jpaging.0.1.min.js"></script>
  3. <linkhref="css/jpaging.css"rel="stylesheet"type="text/css"/>

2. Next you need to insert your html markup into the body tag.

  1. <divid="paging"></div>

3. Create your 'get' function that will select items from database.

  1. function get_data(start_index, end_index){
  2. $.ajax({
  3. type:"POST",
  4. url:'serverpage.aspx',
  5. data:{start_index: start_index,
  6. end_index: end_index},
  7. success:function(data)
  8. {
  9. //create your html
  10. }
  11. });
  12. }

4. Get the total number of items from database and call jPaging plugin.

  1. $.ajax({type:"POST",
  2. url:'serverpage.aspx',
  3. success:function(total)
  4. {
  5. $("#paging").jpaging({
  6. all_items_num: total,
  7. callback: get_data
  8. });
  9. }
  10. });

Example

HTML murkup:

  1. <divid="paging">
  2. <imgsrc=preloader.gif" border="0" alt="" title=""/>
  3. </div>
  4. <divid="demo_tbl">
  5. <imgsrc=preloader.gif" border="0" alt="" title=""/>
  6. </div>

JavaScript:

  1. $("document").ready(function()
  2. {
  3. var items_on_page =5;
  4. var pages_step =5;
  5. function get_data(start_index, end_index){
  6. $.ajax({
  7. type:"POST",
  8. url:"plugins.ashx",
  9. data:{start_index: start_index,
  10. end_index: end_index,
  11. type:"get"},
  12. success:function(html)
  13. {
  14. $("#demo_tbl").html(html);
  15. }
  16. });
  17. }
  18. get_data(1, items_on_page);
  19. $.ajax({
  20. type:"POST",
  21. url:"plugins.ashx",
  22. data:{type:"total"},
  23. success:function(total)
  24. {
  25. $("#paging").jpaging({
  26. all_items_num: total,
  27. callback: get_data,
  28. items_on_page: items_on_page,
  29. pages_step: pages_step
  30. });
  31. }
  32. });
  33. });

Handler class example:

  1. publicclassPluginsHandler:IHttpHandler{
  2. privateDataBase db;
  3. private string type;
  4. publicvoidProcessRequest(HttpContext context)
  5. {
  6. context.Response.ContentType="text/plain";
  7. this.db =newDataBase();
  8. try{
  9. this.type = context.Request.Form["type"];
  10. if(this.type !=""){
  11. switch(this.type){
  12. case"get":{
  13. context.Response.Write(this.Get(context));
  14. break;
  15. }
  16. case"total":{
  17. context.Response.Write(this.db.CountPlugins());
  18. break;
  19. }
  20. }
  21. }
  22. }
  23. catch(Exception ex){
  24. context.Response.Write(ex.Message.ToString()+" "+ ex.StackTrace);
  25. }
  26. }
  27. publicboolIsReusable
  28. {
  29. get {returntrue;}
  30. }
  31. public string Get(HttpContext context){
  32. StringBuilder html =newStringBuilder();
  33. int start_index_int, end_index_int;
  34. bool start_index_num, end_index_num;
  35. string start_index = context.Request.Form["start_index"];
  36. string end_index = context.Request.Form["end_index"];
  37. int count =0;
  38. start_index_num =Int32.TryParse(start_index, out start_index_int);
  39. end_index_num =Int32.TryParse(end_index, out end_index_int);
  40. if(start_index_num && end_index_num){
  41. List plugins =this.db.GetPlugins(start_index_int, end_index_int);
  42. html.AppendLine("<table border='1' cellspacing='0' cellpadding='0' align='center'>");
  43. html.AppendLine("<th width='33%'>Plugin title</th>");
  44. html.AppendLine("<th width='33%'>Description</th>");
  45. html.AppendLine("<th width='33%'>Website</th>");
  46. foreach(Plugin plugin in plugins){
  47. html.AppendLine(this.GetRow(plugin, count));
  48. count++;
  49. }
  50. html.AppendLine("</table>");
  51. }
  52. return html.ToString();
  53. }
  54. public string GetRow(Plugin plugin,int count){
  55. StringBuilder html =newStringBuilder();
  56. string class_name ="odd";
  57. if(count %2==0){
  58. class_name ="even";
  59. }
  60. html.AppendLine("<tr class='"+ class_name +"'>");
  61. html.AppendLine("<td>"+ plugin.Title+"</td>");
  62. html.AppendLine("<td>"+ plugin.Description+"</td>");
  63. html.AppendLine("<td>"+ plugin.Website+"</td>");
  64. html.AppendLine("</tr>");
  65. return html.ToString();
  66. }
  67. }

[转]jQuery AJAX pagination plugin with ASP.NET Server Side的更多相关文章

  1. jQuery AJAX and HttpHandlers in ASP.NET

    https://www.codeproject.com/Articles/170882/jQuery-AJAX-and-HttpHandlers-in-ASP-NET Introduction In ...

  2. jQuery Ajax传递数组到asp.net web api参数为空

    前端: var files = []; files.push({ FileName: "1.jgp", Extension: ".jgp", FileType: ...

  3. jQuery AJAX Call for posting data to ASP.Net page ( not Get but POST)

    the following jQuery AJAX call to an ASP.Net page. $.ajax({ async: true, type: "POST", url ...

  4. ASP.NET MVC WebGrid – Performing true AJAX pagination and sorting 【转】

    ASP.NET MVC WebGrid – Performing true AJAX pagination and sorting FEBRUARY 27, 2012 14 COMMENTS WebG ...

  5. 使用jQuery Pagination Plugin实现分页效果

    最近使用分页这个基础效果较为频繁,而项目前端页面使用的是纯静态的HTML,自己之前写的JSP中的分页就用不成了:项目中也引入了Bootstrap,本来想使用Bootstrap中的分页样式,但发现其样式 ...

  6. ASP.NET使用jQuery AJAX实现MD5加密实例

    一个asp.net ajax例子,使用jquery,实现md5加密.在.NET 4.0,Visual Studio 2010上成功运行. 效果体验:http://tool.keleyi.com/t/m ...

  7. [转]JQuery Ajax 在asp.net中使用总结

    本文转自:http://www.cnblogs.com/acles/articles/2385648.html 自从有了JQuery,Ajax的使用变的越来越方便了,但是使用中还是会或多或少的出现一些 ...

  8. jQuery Ajax 方法调用 Asp.Net WebService 以及调用aspx.cs中方法的详细例子

    一.jQuery Ajax 方法调用 Asp.Net WebService (引自Terry Feng) Html文件 <!DOCTYPE html PUBLIC "-//W3C//D ...

  9. ASP.NET jquery ajax传递参数

    第一种:GET传递 前台 ajax   GET 传递 :即在请求的地址后面加上参数,URL地址长度有显示,安全性低 后台接收:Request.QueryString[“参数名字”]! 例如: func ...

随机推荐

  1. rf常用关键字

    上传文件choose file 用法:choose file     元素定位          文件路径\\文件名 此处注意:复制的路径是/,需全部替换成\\ 清除Clear Element Tex ...

  2. python 趣味强制请吃饭

    # -*- coding: utf-8 -*- import easygui who = easygui.buttonbox("你想请谁吃饭 ?", "luckly qu ...

  3. 浅谈chainer框架

    一 chainer基础 Chainer是一个专门为高效研究和开发深度学习算法而设计的开源框架. 这篇博文会通过一些例子简要地介绍一下Chainer,同时把它与其他一些框架做比较,比如Caffe.The ...

  4. ubuntu - 14.04,安装Go语言(谷歌公司开发的一种语言)

    Go语言下载地址:https://storage.googleapis.com/golang/go1.5.1.linux-amd64.tar.gz 安装: 1,以root身份在shell里执行: ta ...

  5. day03-Linux操作系统目录结构

    一. Linux系统目录表示        ‘/’表示根目录:                                                            ‘.’表示当前目录 ...

  6. jzoj5683. 【GDSOI2018模拟4.22】Prime (Min_25筛+拉格朗日插值+主席树)

    题面 \(n\leq 10^{12},k\leq 100\) 题解 一眼就是一个\(Min\_25\)筛+拉格朗日插值优化,然而打完之后交上去发现只有\(60\)分 神\(tm\)还要用主席树优化-- ...

  7. ajax遍历数据生成下拉框

    <script type="text/javascript">        function GetEQIDList(ModuleID)    {        $. ...

  8. P3613 睡觉困难综合征 LCT+贪心+位运算

    \(\color{#0066ff}{ 题目描述 }\) 由乃这个问题越想越迷糊,已经达到了废寝忘食的地步.结果她发现--晚上睡不着了!只能把自己的一个神经元(我们可以抽象成一个树形结构)拿出来,交给D ...

  9. P1114 “非常男女”计划

    题意:给你一个01串,求满足0和1总数相等的最大字串   $n\ \le\ 10^5$ 1.$O(n^3)$枚举起点终点,统计判断是否成立 2.$O(n^2)$先$O(n)$时间计算01个数的前缀和, ...

  10. STP-6-快速生成树协议-新端口角色,状态和类型以及新链路类型

      IEEE 802.1w快速生成树协议(RSTP)增强了802.1D标准,在设计合理的网络中收敛时间远少于1秒.   端口状态从5个减少到3个 丢弃状态是在端口刚启用时的默认状态,边界端口除外,它的 ...