標籤: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