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