ASP. Easyui--datagrid paging query of ASP. NET background data by Ajax request

Source: Internet
Author: User

JS Front desk Definition code for the DataGrid, as follows

Mygrid = $ (' #mytable '). DataGrid ({fit:true,//Auto SizeHeight: ' Auto ', Rownumbers:true,//Line numberFitcolumns:true, Collapsible:true,//whether it can be collapsed.LOADMSG: ' Data Loading ... ', Singleselect:true,//single-line selectionPagination:true //Show Pagination//columns: [[]]                }); //set up pagination controls$ ("#mytable"). DataGrid (' Getpager '). Pagination ({beforepagetext:"section", Afterpagetext:Page, Displaymsg:"The current {from}-{to} bar data has {total} data", PageSize:100, pagelist: [20, 30, 40, 50, 60, 70, 80, 90, 100], Onbeforerefresh:function() {}, Onrefresh:function(pagenumber, pageSize) {}, Onchangepagesize:function() {}, Onselectpage:function(pagenumber, pageSize) {getData (); }                });

JS Query request code, as follows:

                functionGetData () {varparam = ""; $(". Mynon"). each (function () {                        if($( This). attr ("checked") = = "Checked") param= param + "#" + $ ( This). attr ("id");                    }); if(param! = "") {                        varGrid = $ (' #mytable '); varoptions = Grid.datagrid (' Getpager '). Data ("pagination"). Options;//Options                        varPagenum = Options.pagenumber;//pages                        varTotal = Options.total;//Total                        varmax = Math.ceil (Total/options.pagesize); varpagesize = options.pagesize;//number of rows per page                        varSttime = $ ("#starttime"). ComboBox (' GetText '); varEttime = $ ("#endtime"). ComboBox (' GetText '); $.ajax ({type:"POST", URL:".. /frm/report.aspx/getreport ", Data:{' Begin ': ' + sttime + ' ', ' end ': ' + ettime + ' ', ' param ': ' + param + ' ', ' pagenum ': ' + pagenum + ' ', ' pagesize ': ' "+ page Size + "'}", ContentType:"Application/json; Charset=utf-8 ", DataType:"JSON", Async:false, Success:function(data) {varD = eval (' (' + DATA.D + ') '); Try {                                    $(' #mytable '). DataGrid ("LoadData"), D); } Catch(e) {alert (e); }}, Error:function(ERR) {alert ("Error code:" +err.status);                    }                        }); }                    Else{alert ("Please select the appropriate device!"); }                }              });

Asp. NET background code, such as:

[WebMethod] Public Static stringGetReport (stringBeginstringEndstringParamstringPagenum,stringpagesize) {            stringUserID = httpcontext.current.session["UserID"].            ToString (); string[] paras = param. Split ('#'); stringmeasures ="'";  for(inti =0; I < paras. Length; i++) {measures= measures +"', '"+Paras[i]; } measures= measures +"'"; stringBeginTime = begin +": xx"; stringEndTime = end +": xx"; intTotalCount =0; DataTable DT= DrWater.BLL.infoManager.GetHistoryPageInfo (UserID, BeginTime, endTime, measures, pagenum, pagesize, outtotalcount); List<json.dataItemJson> dataList =NewList<json.dataitemjson>(); if(dt! =NULL)            {                if(dt. Rows.Count >0)                {                     for(inti =0; i < dt. Rows.Count; i++) {Json.dataitemjson Item=NewJson.dataitemjson (); Item.status= dt. rows[i]["Status"].                        ToString ();                    Datalist.add (item); }}} Json.datalistjson Datalistjson=NewJson.datalistjson (); Datalistjson.total=TotalCount; Datalistjson.rows=dataList; JavaScriptSerializer JS=NewJavaScriptSerializer (); Js. Maxjsonlength=int. MaxValue;            stringstr =JS.            Serialize (Datalistjson); returnstr; }

After many debugs, the returned JSON string, although conforming to the data format standard of the Easyui DataGrid, has an error loading the data!

Fix the problem after using eval to convert the JSON string!

ASP. Easyui--datagrid paging query of ASP. NET background data by Ajax request

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.