How to Implement jquery. pagination. js without refreshing pagination

Source: Internet
Author: User

1. Use the plug-in jquery. pagination. js. If this js file is not available, I can send it to you.
First, reference jquery. pagination. js (split page js), with pagination.css (paging style css ).
2. The page js Code is Copy codeThe Code is as follows: <script type = "text/javascript">
Var pageIndex = 0; // initial page index value
Var pageSize = 15; // 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 (<% = pcount %> ,{
Callback: PageCallback, // PageCallback () is the page-turning call function.
Prev_text: "«previous page ",
Next_text: "Next page »",
Items_per_page: pageSize,
Num_edge_entries: 2, // number of entries at the beginning and end of each side
Num_display_entries: 6, // Number of pagination entries in the main part of a consecutive page
Current_page: pageIndex, // index of the current page
});
// Paging call
Function PageCallback (index, jq ){
InitTable (index );
}
// Request data
Function InitTable (pageIndex ){
$. Ajax ({
Type: "POST ",
DataType: "text ",
Url: 'http: // www.jb51.net/tool/Reserver/ManageBuyBatchManage.ashx', // submit the request data to the General processing program
Data: "pageIndex =" + (pageIndex) + "& 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>

3. The code in the page <body> isCopy codeThe Code is as follows: <table width = "100%" border = "0" cellspacing = "0" cellpadding = "0">
<Tr>
<Td width = "60" align = "right"> product name: </td>
<Td width = "200" align = "left"> <input type = "text" id = "txtKeywords" class = "keyword"/> </td>
<Td width = "200" align = "left"> <input id = "search" type = "button" value = "" class = "submit"/> </ td>
<Td> </td>
</Tr>
</Table>
<Table id = "Result" cellspacing = "0" cellpadding = "0">
<Tr>
<Th> item No. </th>
<Th> product name </th>
</Tr>
</Table>
<Div id = "Pagination" class = "right flickr"> </div>

4. The page background code isCopy codeThe Code is as follows: protected int pcount = 0; // The total number of entries.
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
BLL. TbGoods bll = new BLL. TbGoods ();
Pcount = bll. getRecordCount ("Status = '" + (int) Enum. recordStatus. normal + "'"); // obtain the total number of pages, that is, the total number of actual data items. If you do not understand it, select count (*) from Table, the number here.
}
}

5. The General handler fffff. ashx code isCopy codeThe Code is as follows: using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Text;
Using System. Data;
Namespace EShop. Web. Admin. tool. Reserver
{
/// <Summary>
/// Summary of ListBuyBatchManage
/// </Summary>
Public class ListBuyBatchManage: IHttpHandler
{
Public void ProcessRequest (HttpContext context)
{
Context. Response. ContentType = "text/plain ";
String str = string. Empty;
If (context. Request ["pageIndex"]! = Null & context. Request ["pageIndex"]. ToString (). Length> 0)
{
Int pageIndex; // The number of pages.
Int. TryParse (context. Request ["pageIndex"], out pageIndex );
If (context. Request ["pageSize"]! = Null & context. Request ["pageSize"]. ToString (). Length> 0)
{
// Number of entries displayed on the page
Int size = Convert. ToInt32 (context. Request ["pageSize"]);
String data = BindSource (size, pageIndex );
Context. Response. Write (data );
Context. Response. End ();
}
}
}
# Region refreshing pagination
Public string BindSource (int pagesize, int page)
{
BLL. TbGoods bll = new BLL. TbGoods ();
DataSet ds = bll. getListByPage ("Status = '" + (int) Enum. recordStatus. normal + "'", "", pagesize * page + 1, pagesize * (page + 1); // retrieve the ds of the data source.
StringBuilder sb = new StringBuilder ();
If (ds! = Null)
{
Foreach (DataRow row in ds. Tables [0]. Rows)
{
Sb. Append ("<tr> <td> ");
Sb. Append (row ["GoodsUid"]);
Sb. Append ("</td> <td> ");
Sb. Append (row ["GoodsName"]);
Sb. Append ("</td> </tr> ");
}
}
Return sb. ToString ();
}
# Endregion
Public bool IsReusable
{
Get
{
Return false;
}
}
}
}

6.

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.