Ajax無重新整理分頁

來源:互聯網
上載者:User

標籤:blog   http   java   os   io   資料   for   ar   

<!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="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=‘‘>" + 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 = context.Request["pagenum"];//獲得傳過來的頁數                int IPageNUm = Convert.ToInt32(getpagedata);                var adapter = new T_CommentsTableAdapter();//獲得adapter                var data = adapter.GetPagedData((IPageNUm - 1) * 10 + 1, (IPageNUm) * 10);//根據頁數獲得資料                List<Comment> list = new List<Comment>();//建立list                foreach (var item in data)//在list中迴圈輸入Comment屬性PostDate,Msg                  {                    list.Add(new Comment() { PostDate = item.PostDate.ToShortDateString(), Msg=item.Msg });                }                JavaScriptSerializer jss = new JavaScriptSerializer();//序列化list為json                context.Response.Write(jss.Serialize(list));            }        }        public bool IsReusable        {            get            {                return false;            }        }    }    public class Comment    {        public string PostDate { get; set; }        public string Msg { get; set; }    }}

  

select *from(
SELECT Id, PostDate, Msg,Row_Number()over(order by PostDate)rownum FROM dbo.T_Comments
)t
where t.rownum>[email protected] and t.rownum<@endRowIndex

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.