[转]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 ...
随机推荐
- Python--面向对象编程--时钟实例开发
在学习python面向对象编程的时候,心血来潮,决定写一个时钟模型来玩玩,所以就有了现在这个小玩意,不过python这个东西确实是挺好玩的 方法:运用python的tkinter库开发图形化时钟程序 ...
- DNS线路
文章介绍 填写DNS地址时候,比较好记的就114.114.114.114,8.8.8.8,9.9.9.9,几个,但是常用的有哪些呢?这篇文章就简单介绍下了. 前言 两年多前,曾发帖对国内主流公共 DN ...
- [转]关于截取字符串substr和substring两者的区别
subString(start,stop) substr(start,length) substr和substring两个都是截取字符串的. 两者有相同点,如果只是写一个参数,两者的作用都是一样的:就 ...
- .net core 部署在Linux系统上运行的环境搭建总结
安装Linux用的是腾讯云的centos7.5,需要安装有环境有mysql5.7 .netcore2.1 nginx1.14 1.首先是mysql的安装 我用的链接工具是putty,首先root登入 ...
- Failed to export using the options you specified. Please check your options and try again
参考这篇<从ASP.NET传递参数给水晶报表> http://www.cnblogs.com/insus/p/3281114.html 是可以传递参了.但是点击报表的菜单条上的打印图标没 ...
- git 命令总结(转)
结构图: <1> Workspace:工作区 Index / Stage:暂存区 Repository:仓库区(或本地仓库) Remote:远程仓库 一.新建代码库 # 在当前目录新建 ...
- c++语言的学习笔记代码与笔记注释《面向对象部分》
#include <iostream> /*这是C++中关于面向对象部分的具体笔记和代码 */ //定义类的语法形式; //类中的成员项目之间相互引用,直接使用成员; //类外引用成员的时 ...
- Python 文件和异常
一.从文件中读取数据 #!/usr/bin/env python with open('pi') as file_object: contents = file_object.read() print ...
- load xml with xls
you can study xls language in the below link : http://www.w3schools.com/xsl/xsl_languages.asp CSS = ...
- 数据结构11: 栈(Stack)的概念和应用及C语言实现
栈,线性表的一种特殊的存储结构.与学习过的线性表的不同之处在于栈只能从表的固定一端对数据进行插入和删除操作,另一端是封死的. 图1 栈结构示意图 由于栈只有一边开口存取数据,称开口的那一端为“栈顶”, ...