[转]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 ...
随机推荐
- C++笔记--抽象机制
类 一个类就是一个用户定义类型 一个结构体也是一种类.(成员函数),因为不同的结构体中可能会有相同的名字的成员函数,所以我们在定义成员函数的时候就必须给出有关结构体的名字 void Data::ini ...
- C++笔记--类型和声明
布尔量 Eg: bool b1=a==b;//这个例子中,=是赋值,==是判断是否相等,所以先是判断是否相等,a如果等于b,b1的值就是true,否则就是false了 Bool经常被用作检查某些条件是 ...
- bit byte的关系
字 word 字节 byte 位 bit 字长是指字的长度 1字=2字节(1 word = 2 byte) 1字节=8位(1 byte = 8bit) 一个字的字长为2个字节=2*8=16 一个字节 ...
- jQuery的Validate插件
http://www.runoob.com/jquery/jquery-plugin-validate.html 项目中的:: $(function () { $('#createDepartment ...
- FineUI从iis6迁移到iis7.5上遇到的奇葩事情
前天把一台旧服务器上的windows2003+iis6上的fineui项目迁移到了win7+iis7上面来了,没有编译,直接以源码方式运行. 本来运行的好好的,昨天下午在上面用vs2010打开了一下看 ...
- fiddler抓包后Jmeter实现登录接口
登录接口测试时,先要抓取登录接口,我们使用fiddler来抓包,如下图: 然后再使用Jmeter,填写相对于的参数. 查看结果树: 关键在与抓包,搞清楚抓包的信息,可以用fiddler和火狐和谷歌.我 ...
- 毛玻璃CHBlurEffect
1.将需要加入毛玻璃的UI控件传入接口即可 1.1 .h文件 // // 文 件 名:CHBlurEffect.h // // 版权所有:Copyright © 2018年 leLight. All ...
- console的使用
一.显示信息的命令 console.log("normal"); // 用于输出普通信息 console.info("information"); // 用于输 ...
- go语言入门教程百度网盘 mysql图形化操作与数据导入
mysql图形化操作与数据导入 @author:Davie 版权所有:北京千锋互联科技有限公司 数据库存储技术 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库.每个数据库都有一个 ...
- loj #6250. 「CodePlus 2017 11 月赛」找爸爸
#6250. 「CodePlus 2017 11 月赛」找爸爸 题目描述 小 A 最近一直在找自己的爸爸,用什么办法呢,就是 DNA 比对. 小 A 有一套自己的 DNA 序列比较方法,其最终目标是最 ...