No-refreshing paging Code implemented by JQuery and JSon _ jquery

Source: Internet
Author: User
I believe everyone has been on Youku. When you are watching a video, you want to see the comments below the video. After clicking the comments on page 2nd, the whole page is refreshed, the video is played from the beginning, and it is believed that the video will be scolded by users.
Refreshing pagination can solve this problem. The video is played on it. Next, I click the next page to view comments. Currently, most websites do not need refreshing pagination.
The source code is as follows (10 records are displayed on one page ):
Four files are required.
One object file CategoryInfoModel. cs
One SqlHelper SQLHelper. cs
An AJAX server processing program PagedService. ashx
One client calls WSXFY.htm
CategoryInfoModel. cs and SQLHelper. cs I will not write any more, and I know what files it is.
The PagedService. ashx code is as follows:

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"];
// Retrieve the number of pages
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 );
} // Retrieve 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 ();
Ds = SqlHelper. ExecuteDataset (conn, CommandType. Text, strSQL );
List Categoryinfo_list = new List (); // Define an object set
For (int I = 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 an object set to a javascript Object
}
}


The WSXFY.htm code is as follows:

The Code is as follows:



Refreshing pagination

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.