<%@ WebHandler language= "C #" class= "GetData"%> Using System; Using System.Web; Using System.Data.SqlClient; Using System.Data; Using System.Collections.Generic; Using System.Web.Script.Serialization; public class Getdata:ihttphandler { public void ProcessRequest (HttpContext context) { Context. Response.ContentType = "Text/plain"; var PageIndex = context. request["PageIndex"]; String connectionString = @ "Data source=kusesqlexpress;initial catalog=bookshop;integrated security=true"; Determines whether the current index exists, and if it does not exist, gets the total number of records. if (string. IsNullOrEmpty (PageIndex)) { Get the SQL statement for the total number of query records String sql = "SELECT count ( -1) from books"; int count = 0; Int. TryParse (Sqlhelper.executescalar (connectionString, System.Data.CommandType.Text, SQL, NULL). ToString (), out count); Context. Response.Write (count); Context. Response.End (); } When data is obtained from the index Else { int currentpageindex = 1; Int. TryParse (PageIndex, out CurrentPageIndex); sqlparameter[] parms = new sqlparameter[] { New SqlParameter ("@FEILDS", sqldbtype.nvarchar,1000), New SqlParameter ("@PAGE_INDEX", sqldbtype.int,10), New SqlParameter ("@PAGE_SIZE", sqldbtype.int,10), New SqlParameter ("@ORDERTYPE", sqldbtype.int,2), New SqlParameter ("@ANDWHERE", sqldbtype.varchar,1000), New SqlParameter ("@ORDERFEILD", sqldbtype.varchar,100) }; Parms[0]. Value = "*";//Get all fields PARMS[1]. Value = pageindex;//Current page index PARMS[2]. Value = 10;//Page size PARMS[3]. Value = 0;//Ascending order PARMS[4]. Value = "";//Condition statement PARMS[5]. Value = "ID";//Sort field list<book> list = new list<book> (); using (SqlDataReader SDR = Sqlhelper.executereader (connectionString, CommandType.StoredProcedure, "pagination", parms )) { while (SDR. Read ()) { List. ADD (new book {Title = sdr[2]. ToString (), Auhor = sdr[2]. ToString (), publishdate = Sdr[4]. ToString (), ISBN = Sdr[5]. ToString ()}); } } Context. Response.Write (New JavaScriptSerializer (). Serialize (list). ToString ());//JSON format } } public bool IsReusable { get { return false; } } } public class Book { public string Title {get; set;} public string Auhor {get; set;} public string Publishdate {get; set;} public string ISBN {get; set;} } |