No Refresh paging Ajax,jquery,json

Source: Internet
Author: User

1. Database design
Field: Id (int), MSG (varchar (MAX)), Postdate (datetime)

2. Custom SQL Query method (strongly typed dataset)

SelectCount () method for querying the total number of bars
Select COUNT (*) from t_posts

The Getpagedata (Startrowindex,endrowindex) method, which is used to query the specified range, paging function,
Because the over statement is not supported, it is necessary to manually add the parameter, method-right-property, Parameters
Add startRowIndex and Endrowindex, type Int32
SELECT * from
(
Select Id, Msg,postdate,row_number () over (order by postdate) RowNum from t_posts
) T
where T.rownum>[email protected] and T.rownum<[email protected]

3.HTML settings

<id= "Ulcomment"></ul><  Table><id= "Trpage"></TR  ></table>

4. Processing page Settings Wsxfy.ashx

 Public voidProcessRequest (HttpContext context) {context. Response.ContentType="Text/plain"; stringAction = context. request["Action"];//get the action value submitted by the customer            if(Action = ="Getpagecount")//This is the total number of query data bars            {                varadapter =NewT_poststableadapter (); intCount = adapter. SelectCount (). Value;//using a custom SQL method to get the number of bars                intPageCount = Count/Ten;//number of bars divided by 10 to get pages (10 pages)                if(Count%Ten!=0)//The remainder of the number of strips is not divisible by 10, plus 1 .{PageCount++; } context.     Response.Write (PageCount); //Output Pages            }            Else if(Action = ="Getpagedata")//This is the query detail data            {                stringPagenum = context. request["Pagenum"];//get the current page number                intPagenum = Convert.ToInt32 (pagenum);//convert to int type                varadapter =NewT_poststableadapter ();//Create a DataSet                varData = adapter. Getpagedata (Pagenum-1) *Ten+1, (pagenum) *Ten); //use a custom SQL method to get a range of barslist<comment> list =NewList<comment> ();//Create a list type of comment                foreach(varRowinchData//traverse each piece of data{list. ADD (NewComment () {Msg = row. MSG, postdate =row.                              Postdate.toshortdatestring ()}); //add each piece of data to the list} javascriptserializer JSS=NewJavaScriptSerializer ();//Create JsonContext. Response.Write (JSS. Serialize (list));//convert list to JSON type            }        }         Public classComment//Create a class        {             Public stringMSG {Get;Set; }  Public stringpostdate {Get;Set; } }

5. JavaScript settings

<script type= "Text/javascript" >$.post ("Wsxfy.ashx", {"Action": "Getpagecount"},function(data, status) { for(vari = 1; I <= data; i++) {            varTD = $ ("<td><a href=" > "+ i +" </a></td> ");//Cyclic output page number$ ("#trPage"). Append (TD);//attach each TD to each other        }     $("#trPage TD"). Click (function(e) {e.preventdefault (); //block execution of an href address$.post ("Wsxfy.ashx", {"Action": "Getpagedata", "Pagenum": $ ( This). Text ()},function(data, status) {varComments = $.parsejson (data);//using Parsejson conversion$ ("#ulComment"). empty ();//Clear UL           for(vari = 0; i < comments.length; i++) {          varComment =Comments[i]; varLi = $ ("<li>" + comment. Postdate + ":" + comment. MSG + "</li>");//Generate Data$ ("#ulComment"). Append (LI);        }            });    }); });</script>

No Refresh paging Ajax,jquery,json

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.