三、.ashx頁 複製程式碼複製程式碼 程式碼如下 公共類別處理程序:IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; StringBuilder tb = new StringBuilder(); DataBase db = new DataBase(); int pageSize = 10; int pageIndex = 0; 字串型別 = context.Request.Params["type"]; switch (type) { case "first": DataTable dt1 = db.GetDataSet("從測驗中選取前10個*", null).Tables[0]; tb.Append(Common.DataTableToJSON(dt1, true)); //DataTable轉為JSON break; case "next": pageIndex = Convert.ToInt32(context.Request.Params["index"]); DataTable dt2 = db.GetDataSet("select top " pageSize.ToString() " * from test where id> (select max(id) from (select top " (pageSize * pageIndex).ToString() " id from testlect top " (pageSize * pageIndex).ToString() " id from test ) ) ) t)", null).Tables[0]; tb.Append(Common.DataTableToJSON(dt2, true)); 休息; case "pre": pageIndex = Convert.ToInt32(context.Request.Params["index"]); DataTable dt3 = db.GetDataSet("select top " pageSize.ToString() " * from test where id> (select max(id) from (select top " (pageSize * pageIndex).ToString() " id from testlect top " (pageSize * pageIndex).ToString() " id from test ) ) ) t)", null).Tables[0]; tb.Append(JSONHelper.DataTableToJSON(dt)); 休息; } context.Response.Write(tb.ToString()); } public bool IsReusable { 取得 { 回傳 false; } } }
public class Handler : IHttpHandler { public void ProcessRequest(HttpContext context context .Response.ContentType = "文字/純文字"; DataBase db = new DataBase(); int pageSize = 10; int pageIndex = 0; int.TryParse(context.Request.Params["index"], out pageIndex); 字串型別 = context.Request.Params["type"]; string sql = string.Format("select * from ( select row_number() over (order by id) as rowNum,* from test) as t " " where rowNum>{0} and rowNumDataTable dt = db.GetDataSet(sql, null).Tables[0]; context.Response.Write(JSONHelper.DataTableToJSON(dt)); } public bool IsReusable { 取得 { 回傳 false; } } }