[转]jQuery AJAX pagination plugin with ASP.NET Server Side
本文转自: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.
- <scripttype="text/javascript"language="javascript"src="js/jquery-1.5.2.min.js"></script>
- <scripttype="text/javascript"language="javascript"src="js/jquery.jpaging.0.1.min.js"></script>
- <linkhref="css/jpaging.css"rel="stylesheet"type="text/css"/>
2. Next you need to insert your html markup into the body tag.
- <divid="paging"></div>
3. Create your 'get' function that will select items from database.
- function get_data(start_index, end_index){
- $.ajax({
- type:"POST",
- url:'serverpage.aspx',
- data:{start_index: start_index,
- end_index: end_index},
- success:function(data)
- {
- //create your html
- }
- });
- }
4. Get the total number of items from database and call jPaging plugin.
- $.ajax({type:"POST",
- url:'serverpage.aspx',
- success:function(total)
- {
- $("#paging").jpaging({
- all_items_num: total,
- callback: get_data
- });
- }
- });
Example
HTML murkup:
- <divid="paging">
- <imgsrc=preloader.gif" border="0" alt="" title=""/>
- </div>
- <divid="demo_tbl">
- <imgsrc=preloader.gif" border="0" alt="" title=""/>
- </div>
JavaScript:
- $("document").ready(function()
- {
- var items_on_page =5;
- var pages_step =5;
- function get_data(start_index, end_index){
- $.ajax({
- type:"POST",
- url:"plugins.ashx",
- data:{start_index: start_index,
- end_index: end_index,
- type:"get"},
- success:function(html)
- {
- $("#demo_tbl").html(html);
- }
- });
- }
- get_data(1, items_on_page);
- $.ajax({
- type:"POST",
- url:"plugins.ashx",
- data:{type:"total"},
- success:function(total)
- {
- $("#paging").jpaging({
- all_items_num: total,
- callback: get_data,
- items_on_page: items_on_page,
- pages_step: pages_step
- });
- }
- });
- });
Handler class example:
- publicclassPluginsHandler:IHttpHandler{
- privateDataBase db;
- private string type;
- publicvoidProcessRequest(HttpContext context)
- {
- context.Response.ContentType="text/plain";
- this.db =newDataBase();
- try{
- this.type = context.Request.Form["type"];
- if(this.type !=""){
- switch(this.type){
- case"get":{
- context.Response.Write(this.Get(context));
- break;
- }
- case"total":{
- context.Response.Write(this.db.CountPlugins());
- break;
- }
- }
- }
- }
- catch(Exception ex){
- context.Response.Write(ex.Message.ToString()+" "+ ex.StackTrace);
- }
- }
- publicboolIsReusable
- {
- get {returntrue;}
- }
- public string Get(HttpContext context){
- StringBuilder html =newStringBuilder();
- int start_index_int, end_index_int;
- bool start_index_num, end_index_num;
- string start_index = context.Request.Form["start_index"];
- string end_index = context.Request.Form["end_index"];
- int count =0;
- start_index_num =Int32.TryParse(start_index, out start_index_int);
- end_index_num =Int32.TryParse(end_index, out end_index_int);
- if(start_index_num && end_index_num){
- List plugins =this.db.GetPlugins(start_index_int, end_index_int);
- html.AppendLine("<table border='1' cellspacing='0' cellpadding='0' align='center'>");
- html.AppendLine("<th width='33%'>Plugin title</th>");
- html.AppendLine("<th width='33%'>Description</th>");
- html.AppendLine("<th width='33%'>Website</th>");
- foreach(Plugin plugin in plugins){
- html.AppendLine(this.GetRow(plugin, count));
- count++;
- }
- html.AppendLine("</table>");
- }
- return html.ToString();
- }
- public string GetRow(Plugin plugin,int count){
- StringBuilder html =newStringBuilder();
- string class_name ="odd";
- if(count %2==0){
- class_name ="even";
- }
- html.AppendLine("<tr class='"+ class_name +"'>");
- html.AppendLine("<td>"+ plugin.Title+"</td>");
- html.AppendLine("<td>"+ plugin.Description+"</td>");
- html.AppendLine("<td>"+ plugin.Website+"</td>");
- html.AppendLine("</tr>");
- return html.ToString();
- }
- }
[转]jQuery AJAX pagination plugin with ASP.NET Server Side的更多相关文章
- jQuery AJAX and HttpHandlers in ASP.NET
https://www.codeproject.com/Articles/170882/jQuery-AJAX-and-HttpHandlers-in-ASP-NET Introduction In ...
- jQuery Ajax传递数组到asp.net web api参数为空
前端: var files = []; files.push({ FileName: "1.jgp", Extension: ".jgp", FileType: ...
- 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 ...
- 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 ...
- 使用jQuery Pagination Plugin实现分页效果
最近使用分页这个基础效果较为频繁,而项目前端页面使用的是纯静态的HTML,自己之前写的JSP中的分页就用不成了:项目中也引入了Bootstrap,本来想使用Bootstrap中的分页样式,但发现其样式 ...
- ASP.NET使用jQuery AJAX实现MD5加密实例
一个asp.net ajax例子,使用jquery,实现md5加密.在.NET 4.0,Visual Studio 2010上成功运行. 效果体验:http://tool.keleyi.com/t/m ...
- [转]JQuery Ajax 在asp.net中使用总结
本文转自:http://www.cnblogs.com/acles/articles/2385648.html 自从有了JQuery,Ajax的使用变的越来越方便了,但是使用中还是会或多或少的出现一些 ...
- jQuery Ajax 方法调用 Asp.Net WebService 以及调用aspx.cs中方法的详细例子
一.jQuery Ajax 方法调用 Asp.Net WebService (引自Terry Feng) Html文件 <!DOCTYPE html PUBLIC "-//W3C//D ...
- ASP.NET jquery ajax传递参数
第一种:GET传递 前台 ajax GET 传递 :即在请求的地址后面加上参数,URL地址长度有显示,安全性低 后台接收:Request.QueryString[“参数名字”]! 例如: func ...
随机推荐
- Mysql--基本配置
登录的常用参数 mysql -uroot -p 之后再加上密码 mysql -uroot -p+密码 这个方法不安全 mysql -hlocalhost -uroot -p 之后再加上密码 ...
- 写一个Android输入法02——候选窗、转换
上一篇介绍了完成Android输入法的最小化步骤,它只能将按键对应的字符上屏.一般的东亚语言都有一个转换的过程,比如汉语输入拼音,需要由拼音转成汉字再上屏.本文将在前文基础上加入完成转换过程所必需的候 ...
- [haut] 1281: 邪能炸弹 dp
题目描述 正在入侵艾泽拉斯的古尔丹偶然间得到了一颗邪能炸弹,经过研究,他发现这是一颗威力极其巨大且难以控制的炸弹.但是精通邪能的古尔丹突然有了一个大胆的想法,他对炸弹进行了一些小小的改造.这使得炸弹需 ...
- JavaScript高级知识点整理
一.JS中的数组 1.数组的三种定义方式 (1).实例化对象 var aArray=new Array(1,2,3,4,5); (2).快捷创建 var aTwoArray = [1,2,3,&quo ...
- phaser小游戏框架学习(二)
今天继续学习phaser.js.上周写的学习教程主要内容是创建游戏场景,游戏中的显示对象,按钮对象的使用以及如何在不同屏幕大小中完美适配.这篇博客以介绍游戏榜单的渲染更新为主. 代码地址:https: ...
- python 字符串,bytes和hex字符串之间的相互转换
import binascii datastr='13'#string 类型转换为bytedataByte=str.encode(datastr)#byte串 转换为16进制 byte串 ,比如 b' ...
- 内核启动后,lcd显示logo失败
针对-s5pv210,但对其他平台也使用 lcd显示logo失败,若显示成功默认的logo是一只企鹅,但是串口打印“Start display and show logo”,但是LCD屏没有显示 ...
- c++ string.c_str()小结
c++ const char *c_str(); c_str()函数返回一个指向正规C字符串的指针常量, 内容与本string串相同.(其实它指向的是string对象内部真正的char缓冲区),所以返 ...
- 谁能赢呢? BZOJ 2463
题目描述 小明和小红经常玩一个博弈游戏.给定一个n×n的棋盘,一个石头被放在棋盘的左上角.他们轮流移动石头.每一回合,选手只能把石头向上,下,左,右四个方向移动一格,并且要求移动到的格子之前不能被访问 ...
- Unity 使用小技巧
本文介绍我遇到过我Unity使用小技巧,有了这些技巧,项目做起来,溜得飞起 1.快速设置相机的位置 2.固定面板