Jquery. pagination + JSON dynamic refreshing pagination

Source: Internet
Author: User
View code

 1   Using System;
2 Using System. Collections. Generic;
3 Using System. LINQ;
4 Using System. Web;
5 Using System. Web. UI;
6 Using System. Web. UI. webcontrols;
7 Using System. Data;
8
9 Public Partial Class Sqlpage: system. Web. UI. Page
10 {
11 Protected Void Page_load ( Object Sender, eventargs E)
12 {
13 Public Int Pagecount = 0 ;
14 Public Static String Connstring = " Server = 192.168.1.91; database = reportdb; uid = sa; Pwd = 123456 " ;
15 Protected Void Page_load ( Object Sender, eventargs E)
16 {
17 If (! Ispostback ){
18 Pagecount = gettotalpage ();
19 If (Request [ " Pageindex " ]! = Null & Request [ " Pagesize " ]! = Null ){
20 Int Pagesize = convert. toint32 (request [ " Pagesize " ]) = 0 ? 1 : Convert. toint32 (request [ " Pagesize " ]);
21 Int Pageindex = convert. toint32 (request [ " Pageindex " ]) = 0 ? 1 : Convert. toint32 (request [ " Pageindex " ]);
22 Response. Write (getonepage (pagesize, pageindex ));
23 Response. End ();
24 }
25 }
26
27 }
28 Public Int Gettotalpage (){
29 Dbhelper. connstring = connstring;
30 String SQL = " Select count (*) from news " ;
31 Int Rs = convert. toint32 (dbhelper. executescalar (SQL ));
32 Return RS ;}
33 Public String Getonepage ( Int Pagesize, Int Pageindex ){
34 Dbhelper. connstring = connstring;
35 String SQL = String . Empty;
36 SQL = " Select top " + Pagesize + " Newsid, title, smallclassname, author, updatetime from news where newsid not in (select top " + Pagesize * (pageindex- 1 ) + " Newsid from news order by newsid DESC) order by newsid DESC " ;
37 Datatable dt = dbhelper. querybysql (SQL );
38 Return Convertjson. tojson (DT, " News " );
39 }
40 }
41 }

ASPX page:

View code

 1 <% @ Page Language = "  C #  " Autoeventwireup = "  True  " Codefile = "  Sqlpage. aspx. CS  " Inherits = "  Sqlpage " %>
2
3 <! Doctype HTML public " -// W3C // dtd xhtml 1.0 transitional // en " " Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
4 <HTML xmlns = " Http://www.w3.org/1999/xhtml " >
5 <Head runat = " Server " >
6 <Title> </title>
7 </Head>
8 <Body>
9 <Form ID = " Form1 " Runat = " Server " >
10 <Div>
11 <Table id = " Tbldata " Width = " 80% " Cellpadding = " 1 " Cellspacing = " 1 " Bgcolor = " Gray " Style = " Text-align: Center " >
12 <Tr>
13 <TD>
14 Newsid
15 </TD>
16 <TD>
17 Title
18 </TD>
19 <TD>
20 Smallclassname
21 </TD>
22 <TD>
23 Author
24 </TD>
25 <TD>
26 Updatetime
27 </TD>
28 </Tr>
29 </Table>
30 <Div id = " Pagination " >
31 </Div>
32 </Div>
33 </Form>
34 </Body>
35 </Html>
36 <SCRIPT src = " JS/jquery-1.4.2.min.js " Type = " Text/JavaScript " > </SCRIPT>
37 <SCRIPT src = " JS/jquery. pagination. js " Type = " Text/JavaScript " > </SCRIPT>
38 <Script language = " Javascript " Type = " Text/JavaScript " > VaR Pageindex = 0 ;// Page index var pagesize = 20; // Number of entries per page
39 $ (Function (){
40 Init ( 0 );
41 $ ( " # Pagination " ). Pagination (<% = pagecount %> ,{
42 Callback: pagecallback,
43 Prev_text: ' Previous Page ' ,
44 Next_text: ' Next Page ' ,
45 Items_per_page: pagesize,
46 Num_display_entries: 5 ,
47 Current_page: pageindex,
48 Num_edge_entries: 1
49 });
50 Function pagecallback (index, JQ ){
51 Init (INDEX );}
52 });
53 Function Init (pageindex ){
54 $. Ajax ({
55 Type: " Post " ,
56 Datatype: " Text " ,
57 URL: ' Sqlpage. aspx ' ,
58 Data: " Pageindex = " + (Pageindex + 1 ) + " & Pagesize = " + Pagesize, success: function (data ){
59 If (Data! = "" ){
60 $ (" # Tbldata TR: GT (0) " ). Remove (); // Remove all data rows
61 Data = $. parsejson (data );
62 $. Each (data. News, function (index, News ){
63 $ ( " # Tbldata " ). Append (" <Tr bgcolor = 'white'> <TD> " + News. newsid + " </TD> <TD algin = 'left'> " + News. Title + " </TD> <TD> " + News. smallclassname + " </TD> <TD> " + News. Author + " </TD> <TD> " + News. updatetime + " </TD> </tr> " );
64 // Append the returned data to the table.
65 });
66 }
67 }
68 });
69 } </SCRIPT>

 

 

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.