Using Jquery+ajax+json to implement no-refresh paging (ii) in ASP.

Source: Internet
Author: User

<%@ page language= "C #" autoeventwireup= "true" codefile= "PageTest.aspx.cs" inherits= "Renmai_pagetest"%><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<%@ WebHandler language= "C #" class= "Handler1"%>using system;using system.web;using system.data;using  Newtonsoft.json;public class Handler1:ihttphandler {/* HANDLER/HANDLER1.ASHX */protected static int RecordCount    = 0;     protected static DataTable dt = Createdt (); public void ProcessRequest (HttpContext context) {string type=context.        request["type"]; int pageIndex = MSCL. Converthelper.objecttoint (context.        request["PageIndex"]); int pageSize = MSCL. Converthelper.objecttoint (context.        request["PageSize"]); Switch (type) {case "show": #region Paging configuration if (PageIndex = = 0) {PageIndex = 1;                #endregion DataSet ds = new DataSet ();                DataTable dtdata = getpagedtable (dt, PageIndex, pageSize);                                Dtdata.tablename = "Table1";                DataTable Dtcount = new DataTable (); Dtcount.tablename = "Table2";                DTCOUNT.COLUMNS.ADD ("RecordCount"); DTCOUNT.ROWS.ADD (dt.                Rows.Count); Ds.                Tables.add (Dtdata); Ds.                Tables.add (Dtcount);                String json = Jsonconvert.serializeobject (ds, formatting.indented); Context.                Response.Write (JSON);            Break        Default:break; } context.      Response.End ();        } #region Simulation Data private static DataTable Createdt () {DataTable dt = new DataTable (); Dt.        Columns.Add (New DataColumn ("Id", typeof (int)) {defaultvalue = 0}); Dt.        Columns.Add (New DataColumn ("Name", typeof (String)) {defaultvalue = "1"}); Dt.        Columns.Add (New DataColumn ("Sex", typeof (String)) {defaultvalue = "male"}); for (int i = 1; I <=, i++) {dt. Rows.Add (i, "Zhang San" + i.tostring ().        PadLeft (4, ' 0 ')); } RecordCount = dt.        Rows.Count;    return DT; } #endregion//<summary>/Paging the DataTable with a starting page of 1//</summary>//<param name= "DT" ></param>//<param Name= "PageIndex" ></param>//<param name= "PageSize" ></param>//&LT;RETURNS&GT;&LT;/R eturns> public static DataTable getpagedtable (DataTable dt, int PageIndex, int PageSize) {if (pageind        ex = = 0) return DT; DataTable NEWDT = dt.        Copy (); Newdt.        Clear ();        int rowbegin = (PageIndex-1) * PageSize;        int rowend = PageIndex * PageSize; if (rowbegin >= dt.        Rows.Count) return NEWDT; if (rowend > dt. Rows.Count) rowend = dt.        Rows.Count; for (int i = rowbegin; I <= rowend-1; i++) {DataRow NEWDR = Newdt.            NewRow (); DataRow dr = dt.            Rows[i]; foreach (DataColumn column in dt. Columns) {Newdr[column. ColumnName] = Dr[column.            ColumnName]; } NEWDT. Rows.Add (nEWDR);    } return NEWDT; }///<summary>//Get total Pages///</summary>//<param name= "Sumcount" > Number of result sets </pa ram>//<param name= "PageSize" > Number of pages </param>//<returns></returns> Publi        c static int getpagecount (int sumcount, int pageSize) {int page = Sumcount/pagesize;        if (sumcount% pageSize > 0) {page = page + 1;    } return page;        } public bool IsReusable {get {return false; }    }}


Using Jquery+ajax+json to implement no-refresh paging (ii) in ASP.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.