Home  >  Article  >  Web Front-end  >  No-refresh paging code implemented by JQuery and JSon_jquery

No-refresh paging code implemented by JQuery and JSon_jquery

WBOY
WBOYOriginal
2016-05-16 18:02:231005browse

As shown in the picture
No-refresh paging can solve this problem. The video is playing on it. Next, I click on the next page to read the comments. Most websites now have no-refresh paging.
The source code is as follows (I use one page to display 10 records):
Four files are needed
One entity class file CategoryInfoModel.cs
One SqlHelper SQLHelper.cs
One AJAX server-side processing Program PagedService.ashx
A client calls page WSXFY.htm
CategoryInfoModel.cs and SQLHelper.cs. I won’t write them. Everyone knows what the file is
PagedService.ashx. The code is as follows

Copy code The code is as follows:

using System.Web.Script.Serialization;
public void ProcessRequest(HttpContext context )
{
context.Response.ContentType = "text/plain";
string strAction = context.Request["Action"];
//Get the page number
if (strAction = = "GetPageCount")
{
string strSQL = "SELECT COUNT(*) FROM CategoryInfo";
int intRecordCount = SqlHelper.ExecuteScalar(strSQL);
int intPageCount = intRecordCount / 10;
if (intRecordCount % 10 != 0)
{
intPageCount ;
}
context.Response.Write(intPageCount);
}//Get the data of each page
else if (strAction == "GetPageData")
{
string strPageNum = context.Request["PageNum"];
int intPageNum = Convert.ToInt32(strPageNum);
int intStartRowIndex = (intPageNum - 1 ) * 10 1;
int intEndRowIndex = (intPageNum) * 10 1;
string strSQL = "SELECT * FROM ( SELECT ID,CategoryName,Row_Number() OVER(ORDER BY ID ASC) AS rownum FROM CategoryInfo) AS t";
strSQL = " WHERE t.rownum >= " intStartRowIndex " AND t.rownum <= " intEndRowIndex;
DataSet ds = new DataSet();
SqlConnection conn = SqlHelper.GetConnection( ; 0; i < ds.Tables[0].Rows.Count; i )
{
CategoryInfoModel categoryinfo = new CategoryInfoModel();
categoryinfo.CategoryInfoID = Convert.ToInt32(ds.Tables[0] .Rows[i]["ID"]);
categoryinfo.CategoryName = ds.Tables[0].Rows[i]["CategoryName"].ToString();
categoryinfo_list.Add(categoryinfo);
}
JavaScriptSerializer jss = new JavaScriptSerializer();
context.Response.Write(jss.Serialize(categoryinfo_list));//Serialize the entity collection into a javascript object
}
}


WSXFY.htm The code is as follows


No refresh paging