Jquery. pagination. js is used to implement the effect of refreshing new pages.
Tip: In this example, Handler uses the append method of StringBuilder to append HTML. Small Data volumes are acceptable, but big data or layout changes frequently. We recommend that you return data in JSON format, which provides better performance and flexibility!
1. Plug-in parameter list
2. Page Content:
Copy codeThe Code is as follows: <% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. aspx. cs" Inherits = "_ Default" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> Porschev ---- refreshing page flip </title>
<Scripts src = "script/jquery-1.4.1.min.js" type = "text/javascript"> </Script>
<Script src = "Script/jquery. pagination. js" type = "text/javascript"> </script>
<Script src = "Script/tablecloth. js" type = "text/javascript"> </script>
<Link href = "Style/tablecloth.css" rel = "stylesheet" type = "text/css"/>
<Link href = "Style/pagination.css" rel = "stylesheet" type = "text/css"/>
<Script type = "text/javascript">
Var pageIndex = 0; // initial page index value
Var pageSize = 10; // The number of entries displayed on each page is initialized. modify the number of entries displayed. Modify the value here.
$ (Function (){
InitTable (0); // Load event, initialize table data, page index is 0 (first page)
// PageCount indicates the total number of entries. This is a required parameter and other parameters are optional.
$ ("# Pagination"). pagination (<% = pageCount %> ,{
Callback: PageCallback,
Prev_text: 'preput', // text in the previous page button
Next_text: 'Next page', // text in the next pagination button
Items_per_page: pageSize, // Number of display entries
Num_display_entries: 6, // Number of pagination entries in the main part of a consecutive page
Current_page: pageIndex, // index of the current page
Num_edge_entries: 2 // number of entries at the beginning and end of each side
});
// Paging call
Function PageCallback (index, jq ){
InitTable (index );
}
// Request data
Function InitTable (pageIndex ){
$. Ajax ({
Type: "POST ",
DataType: "text ",
Url: 'handler/PagerHandler. ashx', // submit the data to the General processing program request
Data: "pageIndex =" + (pageIndex + 1) + "& pageSize =" + pageSize, // submit two parameters: pageIndex and pageSize)
Success: function (data ){
$ ("# Result tr: gt (0 )"). remove (); // remove the rows in the table whose Id is Result, starting from the second row (this is changed according to the page layout)
$ ("# Result"). append (data); // append the returned data to the table.
}
});
}
});
</Script>
</Head>
<Body>
<Div align = "center">
<H1> Posrchev ---- refreshing pagination
</Div>
<Div id = "container">
<Table id = "Result" cellspacing = "0" cellpadding = "0">
<Tr>
<Th> Number </th>
<Th> name </th>
</Tr>
</Table>
<Div id = "Pagination"> </div>
</Div>
</Body>
</Html>
3. Page. cs File Content:Copy codeThe Code is as follows: using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Public partial class _ Default: System. Web. UI. Page
{
Public string pageCount = string. Empty; // total number of entries
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
PageCount = new PagerTestBLL. PersonManager (). GetPersonCount (). ToString ();
}
}
}
4. Content in Handler:Copy codeThe Code is as follows: <% @ WebHandler Language = "C #" Class = "PagerHandler" %>
Using System;
Using System. Web;
Using System. Collections. Generic;
Using System. Text;
Public class PagerHandler: IHttpHandler {
Public void ProcessRequest (HttpContext context ){
Context. Response. ContentType = "text/plain ";
String str = string. Empty;
// Page count
Int pageIndex;
Int. TryParse (context. Request ["pageIndex"], out pageIndex );
// Number of entries displayed on the page
Int size = Convert. ToInt32 (context. Request ["pageSize"]);
If (pageIndex = 0)
{
PageIndex = 1;
}
Int count;
List <PagerTestModels. Person> list = new PagerTestBLL. PersonManager (). GetAllPerson (size, pageIndex, "", out count );
StringBuilder sb = new StringBuilder ();
Foreach (PagerTestModels. Person p in list)
{
Sb. Append ("<tr> <td> ");
Sb. Append (p. Id. ToString ());
Sb. Append ("</td> <td> ");
Sb. Append (p. Name );
Sb. Append ("</td> </tr> ");
}
Str = sb. ToString ();
Context. Response. Write (str );
}
Public bool IsReusable {
Get {
Return false;
}
}
}
5. Implementation:
Source code download