首页 > 代码库 > Ajax无刷新分页
Ajax无刷新分页
<!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> <title></title> <script src="http://www.mamicode.com/Scripts/jquery-1.4.1.js" type="text/javascript"></script></head><body><ul id="ulcomment"></ul><table><tr id="trPage"></tr></table><script type="text/javascript"> $.post("PagedService.ashx", { "action": "getpagecount" }, function (data, status) { for (var i = 1; i <= data; i++) { var td = $("<td> <a href=http://www.mamicode.com/‘‘>" + i + "</a></td>"); $("#trPage").append(td); } $("#trPage td").click(function (e) { e.preventDefault(); //不要超链接起作用 $.post("PagedService.ashx", { "action": "getpagedata", "pagenum": $(this).text() }, function (data, status) { var comments = $.parseJSON(data); $("#ulcomment").empty(); for (var i = 0; i < comments.length; i++) { var comment = comments[i]; var li = $("<li>提交时间:" + comment.PostDate + "评论" + comment.Msg + "</li>"); $("#ulcomment").append(li); } }); }); }); $.post("PagedService.ashx", { "action": "getpagedata", "pagenum": "1" },//初始化的默认第一页 function (data, status) { var comments = $.parseJSON(data); $("#ulcomment").empty(); for (var i = 0; i < comments.length; i++) { var comment = comments[i]; var li = $("<li>提交时间:" + comment.PostDate + "评论" + comment.Msg + "</li>"); $("#ulcomment").append(li); } }) </script></body> </html>
using System;using System.Collections.Generic;using System.Linq;using System.Web;using Ajax翻页.DAL.DataSetCommentTableAdapters;using System.Web.Script.Serialization;namespace Ajax翻页{ /// <summary> /// PagedService 的摘要说明 /// </summary> public class PagedService : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string action = context.Request["action"]; if (action=="getpagecount") { var adapter = new T_CommentsTableAdapter(); int count = adapter.SelectCount().Value; int pagecount = count / 10; if (count%10!=0) { pagecount++; } context.Response.Write(pagecount); } else if (action == "getpagedata") { string getpagedata = http://www.mamicode.com/context.Request["pagenum"];//获得传过来的页数 int IPageNUm = Convert.ToInt32(getpagedata); var adapter = new T_CommentsTableAdapter();//获得adapter var data = http://www.mamicode.com/adapter.GetPagedData((IPageNUm - 1) * 10 + 1, (IPageNUm) * 10);//根据页数获得数据>
select *from(
SELECT Id, PostDate, Msg,Row_Number()over(order by PostDate)rownum FROM dbo.T_Comments
)t
where t.rownum>=@startRowIndex and t.rownum<@endRowIndex
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。