首页 > 代码库 > 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