前台代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AjaxPage.aspx.cs" Inherits="XML操作.AjaxPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="jquery-3.2-vsdoc2.js" type="text/javascript"></script>
<script src="jquery.pagination.js" type="text/javascript"></script>
<link href="pagination.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
var pageIndex = 0; //页面索引初始值
var pageSize = 15; //每页显示条数初始化,修改显示条数,修改这里即可
$(function () {
InitTable(0); //Load事件,初始化表格数据,页面索引为0(第一页)
//分页,PageCount是总条目数,这是必选参数,其它参数都是可选
$("#Pagination").pagination(<%=pcount%>, {
callback: PageCallback, //PageCallback() 为翻页调用次函数。
prev_text: "« 上一页",
next_text: "下一页 »",
items_per_page:pageSize,
num_edge_entries: 2, //两侧首尾分页条目数
num_display_entries: 6, //连续分页主体部分分页条目数
current_page: pageIndex, //当前页索引
});
//翻页调用
function PageCallback(index, jq) {
InitTable(index);
}
//请求数据
function InitTable(pageIndex) {
$.ajax({
type: "POST",
dataType: "text",
url: 'AjaxPage.ashx', //提交到一般处理程序请求数据
data: "pageIndex=" + (pageIndex) + "&pageSize=" + pageSize, //提交两个参数:pageIndex(页面索引),pageSize(显示条数)
success: function(data) {
$("#Result tr:gt(0)").remove(); //移除Id为Result的表格里的行,从第二行开始(这里根据页面布局不同页变)
$("#Result").append(data); //将返回的数据追加到表格
}
});
}
}); </script>
</head> <body>
<form id="form1" runat="server">
<table id="Result" cellspacing="0" cellpadding="0">
<tr>
<th>商品编号</th>
<th>商品名称</th>
</tr>
</table>
<div id="Pagination" class="right flickr"></div>
<%-- 分页使用的样式(可选)
<div id="Pagination" class="meneame"></div>
<div id="Pagination" class="black"></div>
<div id="Pagination" class="quotes"></div>
<div id="Pagination" class="scott"></div> --%>
</form>
</body>
</html>

后台代码:

protected string pcount=string.Empty;           //总条数
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
pcount = SQLHelper.GetDataSet("select count(*) from K_SysModuleNode").Rows[][].ToString();
}
}

Ajax处理程序:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Text;
using KingTop.Common;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web.Script.Serialization; namespace XML操作
{
/// <summary>
/// AjaxPage1 的摘要说明
/// </summary>
public class AjaxPage1 : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
String str = string.Empty; if (context.Request["pageIndex"] != null && context.Request["pageIndex"].ToString().Length > )
{
int pageIndex; //具体的页面数
int.TryParse(context.Request["pageIndex"], out pageIndex);
if (context.Request["pageSize"] != null && context.Request["pageSize"].ToString().Length > )
{
//页面显示条数
string pageSize = context.Request["pageSize"].ToString();
string data = BindSource(pageSize,pageIndex.ToString());
context.Response.Write(data);
context.Response.End();
}
}
} public bool IsReusable
{
get
{
return false;
}
} #region 绑定
/// <summary>
/// 剧院之窗列表
/// </summary>
private string BindSource(string pageSize, string pageIndex)
{
string sql = string.Format("select NodeID,NodeCode,NodeName from K_SysModuleNode");
int pagesize = int.Parse(pageSize);
int pageindex = int.Parse(pageIndex)+; string order = " NodeCode desc ";
SqlParameter[] sqlparam = new SqlParameter[] {
new SqlParameter("@NewPageIndex",pageindex),
new SqlParameter("@PageSize",pagesize),
new SqlParameter("@order",order),
new SqlParameter("@strSql",sql)
};
StringBuilder text = new StringBuilder();
DataSet ds = SQLHelper.ExecuteDataSet(SQLHelper.ConnectionStringLocalTransaction,
CommandType.StoredProcedure, "proc_Pager", sqlparam);
if (ds != null && ds.Tables.Count > )
{
foreach (DataRow row in ds.Tables[].Rows)
{
text.Append("<tr><td>");
text.Append(row["NodeID"]);
text.Append("</td><td>");
text.Append(row["NodeCode"]);
text.Append("</td><td>");
text.Append(row["NodeName"]);
text.Append("</td></tr>");
} }
return text.ToString(); }
}
#endregion
}

所使用的方法:

 /// <summary>
/// 分页存储过程
/// </summary>
/// <param name="connectionString">连接语句</param>
/// <param name="cmdType">sql语句类型</param>
/// <param name="cmdText">存储过程名称</param>
/// <param name="commandParameters">参数名</param>
/// <returns></returns>
public static DataSet ExecuteDataSet(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
{
SqlCommand cmd = new SqlCommand();
SqlConnection conn = new SqlConnection(connectionString);
DataSet ds = new DataSet();
try
{
PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(ds);
return ds;
}
catch
{
conn.Close();
throw;
}
finally
{
conn.Close();
}
}
 /// <summary>
/// Prepare a command for execution
/// </summary>
/// <param name="cmd">SqlCommand object</param>
/// <param name="conn">SqlConnection object</param>
/// <param name="trans">SqlTransaction object</param>
/// <param name="cmdType">Cmd type e.g. stored procedure or text</param>
/// <param name="cmdText">Command text, e.g. Select * from Products</param>
/// <param name="cmdParms">SqlParameters to use in the command</param>
private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParms)
{
if (conn.State != ConnectionState.Open)
{
conn.Open();
} cmd.Connection = conn;
cmd.CommandText = cmdText; if (trans != null)
{
cmd.Transaction = trans;
} cmd.CommandType = cmdType; if (cmdParms != null)
{
foreach (SqlParameter parm in cmdParms)
cmd.Parameters.Add(parm);
}
}

分页存储过程:

ALTER PROC [dbo].[proc_Pager]
@NewPageIndex int,--当前页码
@PageSize int,--分页条数
@order varchar(64),
@strSql nvarchar(max) --sql语句
as
DECLARE @str varchar(8000)
BEGIN
SET @str = 'SELECT COUNT(1) FROM ('+@strSql+')T'
SET @str = @str+' SELECT * FROM (SELECT row_number() over(order by '+@order+') as Rownum,* FROM('+@strSql+')T1)T '
END
SET @str=@str+' where Rownum between '+cast((@NewPageIndex-1)*@PageSize+1 as varchar(20))+' and '+cast(@NewPageIndex*@PageSize as varchar(20))
--IF LEN(@order)<>0
--SET @str=@str+' order by '+@order
EXEC(@str)

Ajax无刷新分页的更多相关文章

  1. ajax 无刷新分页

    //ajax 无刷新分页1.前台要做的 滑动时 当前page+1,通过page ajax请求后台接口获取数据将数据进行拼装;2.后台要做的 做分页接口返回json数据前台判断触发请求条件: var p ...

  2. thinkphp ajax 无刷新分页效果的实现

    思路:先做出传统分页效果,然后重新复制一份Page.class.php类,对它进行修改,把js中的函数传到page类中,把上一页.下一页.首页.尾页.链接页中的url地址改成js控制的函数,模板页面中 ...

  3. 关于Ajax无刷新分页技术的一些研究 c#

    关于Ajax无刷新分页技术的一些研究 c# 小弟新手,求大神有更好的解决方案,指教下~ 以前做项目,用过GridView的刷新分页,也用过EasyUI的封装好的分页技术,最近在老项目的基础上加新功能, ...

  4. thinkphp下实现ajax无刷新分页

    1.前言 作为一名php程序员,我们开发网站主要就是为了客户从客户端进行体验,在这里,thinkphp框架自带的分页类是每次翻页都要刷新一下整个页面,这种翻页的用户体验显然是不太理想的,我们希望每次翻 ...

  5. 学习笔记之AJAX无刷新分页

    利用AJAX实现无刷新分页技术原理: 其主要是利用AJAX的异步处理机制,实现数据的异步传递,它隐藏了客户端向服务端请求数据的状态,在客户端表现为无刷新的显示状态. 实现分页的步骤: 1.客服端点击页 ...

  6. ThinkPhp 3.2 ajax无刷新分页(未完全改完,临时凑合着用)

    临时更改后的page类(很多地方没修改...因为笔者PHP没学好..)如下: <?phpnamespace Fenye\libs; /**  file: page.class.php   完美分 ...

  7. jquery+jquery.pagination+php+ajax 无刷新分页

    <!DOCTYPE html> <html ><head><meta http-equiv="Content-Type" content= ...

  8. SUI分页组件和avalon搞定ajax无刷新分页

    <div ms-controller="main"> <h2 class="pagination-centered">{{ title ...

  9. php+ajax无刷新分页原生ajax实现分页最简单完整实例-完整代码,

    展示页面:index.html <html><script> function ajax_show() { // 获取当前页 var page =1; var xhr = ne ...

随机推荐

  1. 常见面试问题 - Useful Links

    1. Data Structure & Algorithm - 二叉树 http://baike.baidu.com/link?url=jKNdOOipbp-gloTVmSU4PT2mVB94 ...

  2. Linux刷新DNS缓存

    网上查了下,发现linux刷新dns的缓存方法都是: sudo /etc/init.d/nscd restart 但是在我的机器上,发现提示命令找不到: sudo /etc/init.d/nscd: ...

  3. python 格式化 json输出

    利用python格式化json 字符串输出. $ echo '{"json":"obj"}' | python -m json.tool 利用python -m ...

  4. Junit测试中的setup和teardown 和 @before 和 @After 方法

    这几天做Junit测试接触到了setup和teardown两个方法,简单的可以这样理解它们,setup主要实现测试前的初始化工作,而teardown则主要实现测试完成后的垃圾回收等工作. 需要注意的是 ...

  5. CRC

    #define POLY 0x1021 /** * Calculating CRC-16 in 'C' * @para addr, start of data * @para num, length ...

  6. css兼容tooltip提示框方法

    最终效果图: 基本原理 先设定一个背景色的普通div盒子,然后使用上篇post得到的三角型图标,把div盒子设置为相对定位模式,三角型图标设置为绝对定位,位置相对于div盒子,调整到合适的位置.这样就 ...

  7. mac安装Mysql官方示例数据库employee

    1. 下载地址 https://launchpad.net/test-db/employees-db-1/1.0.6 2. 执行命令 /usr/local/mysql/bin/mysql -t -u ...

  8. navicat for mysql

    下载地址:https://www.navicat.com/cht/download 详情:http://baike.baidu.com/link?url=zo3CUg3HC5XUHkz4YqXO6Em ...

  9. smarty基本语法

    smarty基本语法: 1.注释:<{* this is a comment *}>,注意左右分隔符的写法,要和自己定义的一致. <{* I am a Smarty comment, ...

  10. PHP对自己I/O流访问的封装(转)

    php://stdin:访问PHP进程相应的输入流,比如用在获取cli执行脚本时的键盘输入. php://stdout:访问PHP进程相应的输出流. php://stderr:访问PHP进程相应的错误 ...