asp.net No refresh pagination Instance Code _ Practical Tips

Source: Internet
Author: User

Data Class Code:

Copy Code code as follows:

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Data;
Using System.Data.SqlClient;
Using System.Collections;
Using System.Reflection;

Namespace DAL
{
public class Usermanageclass
{
<summary>
Get Total Pages
</summary>
<returns> Total Pages </returns>
public int Getpagecount ()
{
int counts;
String sqlstr = "SELECT count (0) from [User]";
counts = new SQLHelper (). Content (Sqlstr, CommandType.Text);
return counts;
}
<summary>
Remove the contents of each page
</summary>
<param name= "Satrpage" > Start Page </param>
<param name= "EndPage" > End pages </param>
<returns> content of each page </returns>
Public DataTable getpagedate (string satrpage, String endpage)
{
DataTable DT;
String sqlstr = @ "SELECT * FROM
(SELECT *, Row_number () over (order by ID) as No_ from [User]) AA
where aa.no_ between ' "+satrpage+" ' and ' "+endpage+" ";
DT = new SQLHelper (). ExecuteQuery (Sqlstr, CommandType.Text);
return DT;
}

       ///<summary>
       / Converts a DataTable to a list
       ///</summary>
        ///<typeparam name= "T" > Type </TYPEPARAM> of entity objects;
        ///<param name= "DT" > Datatable</param> to convert;
        ///<returns></returns>
        public  list<t > datatabletoentitylist<t> (DataTable dt)
        {
             list<t> entiylist = new list<t> ();

Type EntityType = typeof (T);
propertyinfo[] entityproperties = Entitytype.getproperties ();

foreach (DataRow row in dt. Rows)
{
T entity = activator.createinstance<t> ();

foreach (PropertyInfo propinfo in entityproperties)
{
if (dt. Columns.contains (Propinfo.name))
{
if (!row. IsNull (Propinfo.name))
{
Propinfo.setvalue (Entity, Row[propinfo.name], NULL);
}
}
}

Entiylist.add (entity);
}

return entiylist;
}


}
}

PageService.ashx.cs General Handler code:

Copy Code code as follows:

Using System;
Using System.Collections;
Using System.Data;
Using System.Linq;
Using System.Web;
Using System.Web.Services;
Using System.Web.Services.Protocols;
Using System.Xml.Linq;
Using System.Data.SqlClient;
Using DAL;
Using System.Web.Extensions;
Using System.Web.Script.Serialization;
Using Model;
Using System.Web.UI.MobileControls;
Using System.Collections.Generic;

Namespace Landingsystem
{
<summary>
Summary description of $codebehindclassname $
</summary>
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]
public class Pageservice:ihttphandler
{

public void ProcessRequest (HttpContext context)
{
Context. Response.ContentType = "Text/plain";
String action = context. Request["Action"];
if (action = = "Getpagecount")
{
int counts = new Usermanageclass (). Getpagecount ();
int page = COUNTS/3;
if (counts% 3!= 0)
{
page++;
}
Context. Response.Write (page);
}
else if (action = = "Getpagedata")
{
int pageno = Convert.ToInt32 (context. request["PageNo"]);
String satrpage = ((pageNo-1) * 3 + 1). ToString ();
String endpage = (PageNo * 3). ToString ();
DataTable dt= New Usermanageclass (). Getpagedate (Satrpage, endpage);
ilist<registermodel> data = Modelconverthelper<registermodel>. Converttomodel (DT);
ilist<registermodel> data = new Usermanageclass (). datatabletoentitylist<registermodel> (DT);
var p1 = data. Select (c => new {c.name,c.phone});
#region Waste Code
var p1 = data. Select (c => new {c.name,c.phone});
var p1=data. Select (dr=>new {dr["Name"). ToString (), dr["Phone"]. ToString ()});


var T_model = new list<registermodel> ();
var p3 = T_model. Select (c => new {c.name, c.phone});

               //var P2=data. Select (C=>new {})
                 #endregion
                JavaScriptSerializer JSS = new JavaScriptSerializer ();
                context. Response.Write (JSS. Serialize (p1));
           }
       }

public bool IsReusable
{
Get
{
return false;
}
}
}
}

ASPX page code:

Copy Code code as follows:

<title> Untitled Page </title>

<script src= "Js/jquery-latest.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >
$ (function () {
//-----------------------------------------------------------
function Getpagedata (PageNo) {//method of obtaining data from a page
$.post ("Pageservice.ashx", {"Action": "Getpagedata", "PageNo":p ageno},function (data,status) {
if (status== "success") {
$ ("#Comment"). empty ();
var comments=$.parsejson (data); Deserializes the JSON data.
for (Var i=0;i<comments.length;i++) {
var row=comments[i];
var li= $ ("<li>" +row. Name+ ":" +row. Phone+ "</li>");
$ ("#Comment"). Append (LI); Each data is removed to create an Li and append into the comment/ul.
}
}
});
}
//-------------------------------------------------------------------
Getpagedata (1); First entry to the page, see the first page of the data
//----------------------------------------------------------------/
Gets all the pages and initializes the page-splitting button
$.post ("Pageservice.ashx", {"Action": "Getpagecount"},function (data,status) {
if (status== "success") {
var tr1=$ ("<tr></tr>");
var pageno=parseint (data);
for (Var i=1;i<=pageno;i++) {
var td=$ ("<td><a href= ' >" +i+ "</a></td>");
Tr1.append (TD);
}
$ ("#pageNo"). append (TR1);
$ ("#pageNo a"). Click (function (e) {//page number is created, the click event is monitored for each page number.
E.preventdefault (); Cancel the default jump behavior for a
Getpagedata ($ (this). html ()); Click on the page to perform the operation of fetching data.
});
}
});
//----------------------------------------------------------------------------
});
</script>

<body>
<table>
<tr>
<td>
<ul id= "Comment" ></ul>
</td>
</tr>
</table>
<br/>
Pages:
<table id= "PageNo" ></table>
</body>

ModelConvertHelper.cs (convert DataTable to list common Class) code:

Copy Code code as follows:

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Collections;
Using System.Data;
Using System.Reflection;

Namespace DAL
{
public class modelconverthelper<t> where T:new ()
{
public static ilist<t> Converttomodel (DataTable DT)
{
ilist<t> ts = new list<t> ();
Type type=typeof (T);
String tempname = "";
foreach (DataRow dr in Dt. Rows)
{
T t = new t ();
To obtain the public properties of this model
propertyinfo[] Propertys = T.gettype (). GetProperties ();
foreach (PropertyInfo pi in Propertys)
{
Tempname = Pi. Name;
Check if the DataTable contains this column
if (dt. Columns.contains (Tempname))
{
Determine if this property has a setter
if (!pi. CanRead) continue;
Object value = Dr[tempname];
if (value!= dbnull.value)
if (pi. PropertyType = = typeof (int))
{
Pi. SetValue (t, Convert.ToInt32 (value), NULL);
}
else if (pi. PropertyType = = typeof (String)
{
Pi. SetValue (t, value. ToString (), NULL);
}
Pi. SetValue (t, value, NULL);
}
}
Ts. ADD (t);
}
return TS;
}


}
}

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.