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!=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)twhere t.rownum>=@startRowIndex and t.rownum<@endRowIndex
转载于:https://www.cnblogs.com/blackHorseplan/p/3907010.html
相关资源:tp3.2 ajax无刷新分页