JQuery and Ajax Paging

Source: Internet
Author: User

JQuery and Ajax Paging
1. Preview

2. HTML code

 
Template Name Text message content Operation

3. JS Code
// Load the text message template content-Paging function TemplateAjax () {$ ('# TemplateTable tbody tr '). remove (); // clear Table tbody AjaxPage (1, PageSize);} // the current page, showing the number of items function AjaxPage (curpage, PageSize) {// save var ProvinceId =$ ('# MainContent_ddlsheng '). val (); // city var CityId = $ ('# MainContent_ddlshi '). val (); $. ajax ({cache: false, url:/ajaxpage/getajax. aspx? T = smsplateformtemplateajaxpage & ProvinceId = + ProvinceId + & CityId = + CityId + & CurPage = + curpage + & PageSize = + PageSize + & a = + Math. random (), dataType: 'json', success: function (data) {if (data! = Null) {var str = ''; for (var I in data [Data]) {var Content = data [Data] [I] [SmsTemplateContent]; if (Content. length> = 60) {Content = Content. substring (0, 60);} str + = + data [Data] [I] [SmsTemplateName] ++ Content +;}$ ('# TemplateTable tbody'{.html (str); RecordCount = data [RecordCount]; Comment ('{pagecount'{.html (RecordCount );}}})} // on the home page, Previous Page, next page, and last page, click function PageIndexClick (obj) {// current page var CurrenPageSize = required ('{currenpagesize'{.html (); // id var type = $ (obj ). attr ('id'); // home page if (type = 'firstpage') {CurrenPageSize = 1; AjaxPage (CurrenPageSize, PageSize); Response ('{currenpagesize'{.html ('1 ');} // previous else if (type = 'Oppage') {if (CurrenPageSize> 1) {CurrenPageSize = parseInt (CurrenPageSize)-1;} else {CurrenPageSize = 1;} AjaxPage (CurrenPageSize, PageSize ); upper (CurrenPageSize);} // next else if (type = 'nextpage') {var size = parseInt (CurrenPageSize) + 1; var maxpage = RecordCount % PageSize = 0? ParseInt (RecordCount/PageSize): (parseInt (RecordCount/PageSize) + 1); if (size <= maxpage) {CurrenPageSize = parseInt (CurrenPageSize) + 1} AjaxPage (response, pageSize); ('{currenpagesize'{.html (CurrenPageSize);} // else if (type = 'lastpage') {CurrenPageSize = (RecordCount % PageSize = 0? ParseInt (RecordCount/PageSize): parseInt (RecordCount/PageSize) + 1); AjaxPage (CurrenPageSize, PageSize); interval (CurrenPageSize); }}// Delete the template function partition (id) {$. ajax ({cache: false, url:/ajaxpage/getajax. aspx? T = smsplateformtemplateajaxdelete & Id = + id + & a = + Math. random (), ype: 'json', success: function (data) {if (data! = Null) {alert (data ['result']); AjaxPage (1, PageSize );}}});}

4. C # background code
If (Request. queryString [t] = smsplateformtemplateajaxpage) {try {string ProvinceId = Request. queryString [ProvinceId]; string CityId = Request. queryString [CityId]; int CurPage = 1; // current page int. tryParse (Request. queryString [CurPage], out CurPage); int PageSize = 5; // The number of data entries displayed on each page. tryParse (Request. queryString [PageSize], out PageSize); StringBuilder sb = new StringBuilder (); sb. append (1 = 1 and (delete _ Flag is null or delete_flag = 0); // saves if (ProvinceId! = Null &&! String. IsNullOrEmpty (ProvinceId) & ProvinceId! = 0) {sb. Append (string. Format (and ProvinceId = {0}, ProvinceId. Trim ();} // city if (! String. IsNullOrEmpty (CityId) & CityId! = 0 & CityId! = Null) {sb. append (string. format (and CityId = {0}, CityId. trim ();} PageArgs pageArgs = new PageArgs (); pageArgs. pageSize = PageSize; pageArgs. pageIndex = CurPage; pageArgs. tableName = D_SMSTemplate; pageArgs. primaryKey = Id; pageArgs. fields =; pageArgs. filter = sb. toString (); pageArgs. order = create_time desc; IList
 
  
List = new SMSTemplateBLL (). GetSMSTemplateAll (ref pageArgs); List
  
   
> Li = new List
   
    
> (); Dictionary
    
     
Dic = new Dictionary
     
      
(); Dic. add (RecordCount, pageArgs. recordCount); // The total number of dic entries. add (Data, list); JavaScriptSerializer serializer = new JavaScriptSerializer (); var result = serializer. serialize (dic); Response. write (result);} catch {Response. write (null );}}
     
    
   
  
 


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.