jQuery、Ajax分頁

來源:互聯網
上載者:User

jQuery、Ajax分頁
1、預覽

2、HTML代碼

 
模板名稱 簡訊內容 操作
  
3、JS代碼
//載入簡訊模板內容-分頁function TemplateAjax() {    $('#TemplateTable tbody tr').remove();//清空Table tbody    AjaxPage(1, PageSize);}//當前頁,顯示條數function AjaxPage(curpage, PageSize) {    //省    var ProvinceId = $('#MainContent_ddlsheng').val();    //市    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];                $('#pageCount').html(RecordCount);            }        }    })}//首頁、上一頁、下一頁、尾頁點擊function PageIndexClick(obj) {    //當前第幾頁    var CurrenPageSize = $('#CurrenPageSize').html();    //id    var type = $(obj).attr('id');    //首頁    if (type == 'FirstPage') {        CurrenPageSize = 1;        AjaxPage(CurrenPageSize, PageSize);        $('#CurrenPageSize').html('1');    }        //上一頁    else if (type == 'TopPage') {        if (CurrenPageSize > 1) {            CurrenPageSize = parseInt(CurrenPageSize) - 1;        } else {            CurrenPageSize = 1;        }        AjaxPage(CurrenPageSize, PageSize);        $('#CurrenPageSize').html(CurrenPageSize);    }        //下一頁    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(CurrenPageSize, PageSize);        $('#CurrenPageSize').html(CurrenPageSize);    }        //尾頁    else if (type == 'LastPage') {        CurrenPageSize = (RecordCount % PageSize == 0 ? parseInt(RecordCount / PageSize) : parseInt(RecordCount / PageSize) + 1);        AjaxPage(CurrenPageSize, PageSize);        $('#CurrenPageSize').html(CurrenPageSize);    }}//刪除模板function TemplateDelete(id) {    $.ajax({        cache: false,        url: /ajaxpage/getajax.aspx?t=smsplateformtemplateajaxdelete&Id= + id + &a= + Math.random(),        dataType: 'json',        success: function (data) {            if (data != null) {                alert(data['result']);                AjaxPage(1, PageSize);            }        }    });}

4、C#後台代碼
           if(Request.QueryString[t] == smsplateformtemplateajaxpage)            {                try                {                    string ProvinceId = Request.QueryString[ProvinceId];                    string CityId = Request.QueryString[CityId];                    int CurPage = 1;//當前第幾頁                    int.TryParse(Request.QueryString[CurPage], out CurPage);                    int PageSize = 5;//每頁顯示多少條資料                    int.TryParse(Request.QueryString[PageSize], out PageSize);                    StringBuilder sb = new StringBuilder();                    sb.Append( 1=1 and (delete_flag IS NULL  OR  delete_flag=0));                    //省                    if (ProvinceId != null && !string.IsNullOrEmpty(ProvinceId) && ProvinceId != 0)                    {                        sb.Append(string.Format( and ProvinceId={0} , ProvinceId.Trim()));                    }                    //市                    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);//總條數                    dic.Add(Data, list);                    JavaScriptSerializer serializer = new JavaScriptSerializer();                    var result = serializer.Serialize(dic);                    Response.Write(result);                }                catch                {                    Response.Write(null);                }            }


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.