当前位置:  开发笔记 > 后端 > 正文

JqG​​rid addJSONData + ASP.NET 2.0 WS

如何解决《JqG​​ridaddJSONData+ASP.NET2.0WS》经验,为你挑选了1个好方法。

我有点迷茫.我试图实现基于JqGrid的解决方案,并尝试使用函数作为数据类型.我已经通过这本书设置了所有内容,我调用了WS并获得了JSON,我在ajax调用的客户端获得了成功,并且我使用"绑定"jqGrid,addJSONData但网格仍为空.我现在没有任何线索...同一页面上的其他"本地"样本没有问题(jsonstring ...)

我的WS方法如下:

[WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string GetGridData()  
         {  
             // Load a list 
             InitSessionVariables();
             SA.DB.DenarnaEnota.DenarnaEnotaDB db = new SAOP.SA.DB.DenarnaEnota.DenarnaEnotaDB();
             DataSet ds = db.GetLookupForDenarnaEnota(SAOP.FW.DB.RecordStatus.All);

             // Turn into HTML friendly format  
             GetGridData summaryList = new GetGridData();

             summaryList.page = "1";
             summaryList.total = "10";
             summaryList.records = "160";
             int i = 0;
             foreach (DataRow dr in ds.Tables[0].Rows)  
             {
                 GridRows row = new GridRows();
                 row.id = dr["DenarnaEnotaID"].ToString();
                 row.cell = "[" + "\"" + dr["DenarnaEnotaID"].ToString() + "\""
                                       + "," + "\"" + dr["Kratica"].ToString() + "\""
                                       + "," + "\"" + dr["Naziv"].ToString() + "\""
                                       + "," + "\"" + dr["Sifra"].ToString() + "\""

                          + "]";
                 summaryList.rows.Add(row);
             }  
             return JsonConvert.SerializeObject(summaryList);

         }

我的ASCX代码是这样的:

jQuery(document).ready(function(){
jQuery("#list").jqGrid({
                        datatype : function (postdata) { jQuery.ajax({ url:'../../AjaxWS/TemeljnicaEdit.asmx/GetGridData', 
                                                                       data:'{}', 
                                                                       dataType:'json', 
                                                                       type: 'POST',
                                                                       contentType: "application/json; charset=utf-8",
                                                                       complete: function(jsondata,stat){ 
                                                                                                         if(stat=="success") 
                                                                                                         { 
                                                                                                              var clearJson = jsondata.responseText;

                                                                                                              var thegrid = jQuery("#list")[0]; 
                                                                                                              var myjsongrid = eval('('+clearJson+')');
                                                                                                              alfs
                                                                                                              thegrid.addJSONData(myjsongrid.replace(/\\/g,''));
                                                                                                         } 
                                                                                                        } 
                                                                     }
                                                                    ); 
                                                       }, 
                        colNames:['DenarnaEnotaID','Kratica', 'Sifra', 'Naziv'], 
                        colModel:[ 
                                   {name:'DenarnaEnotaID',index:'DenarnaEnotaID', width:100}, 
                                   {name:'Kratica',index:'Kratica', width:100}, 
                                   {name:'Sifra',index:'Sifra', width:100}, 
                                   {name:'Naziv',index:'Naziv', width:100}], 

                        rowNum:15, 
                        rowList:[15,30,100], 
                        pager: jQuery('#pager'), 
                        sortname: 'id', 
                      //  loadtext:"Nalagam zapise...",
                       // viewrecords: true, 
                        sortorder: "desc", 
                       // caption:"Vrstice", 
                       // width:"800",
                        imgpath: "../Scripts/JGrid/themes/basic/images"}); 

               });

从WS我得到这样的JSON:

{”page”:”1?,”total”:”10?,”records”:”160?,”rows”:[{"id":"18","cell":"["18","BAM","Konvertibilna marka","977"]“},{”id”:”19?,”cell”:”["19","RSD","Srbski dinar","941"]“},{”id”:”20?,”cell”:”["20","AFN","Afgani","971"]“},{”id”:”21?,”cell”:”["21","ALL","Lek","008"]“},{”id”:”22?,”cell”:”["22","DZD","Alžirski dinar","012"]“},{”id”:”23?,”cell”:”["23","AOA","Kvanza","973"]“},{”id”:”24?,”cell”:”["24","XCD","Vzhodnokaribski dolar","951"]“},{”id”:”25?,”cell”:”

………………

["13","PLN","Poljski zlot","985"]“},{”id”:”14?,”cell”:”["14","SEK","Švedska krona","752"]“},{”id”:”15?,”cell”:”["15","SKK","Slovaška krona","703"]“},{”id”:”16?,”cell”:”["16","USD","Ameriški dolar","840"]“},{”id”:”17?,”cell”:”["17","XXX","Nobena valuta","000"]“},{”id”:”1?,”cell”:”["1","SIT","Slovenski tolar","705"]“}]}

我已经注册了这个JavaScript:

clientSideScripts.RegisterClientScriptFile("prototype.js", CommonFunctions.FixupUrlWithoutSessionID("~/WebUI/Scripts/prototype-1.6.0.2.js"));

clientSideScripts.RegisterClientScriptFile("jquery.js", CommonFunctions.FixupUrlWithoutSessionID("~/WebUI/Scripts/JGrid/jquery.js"));
clientSideScripts.RegisterClientScriptFile("jquery.jqGrid.js", CommonFunctions.FixupUrlWithoutSessionID("~/WebUI/Scripts/JGrid/jquery.jqGrid.js"));
clientSideScripts.RegisterClientScriptFile("jqModal.js", CommonFunctions.FixupUrlWithoutSessionID("~/WebUI/Scripts/JGrid/js/jqModal.js"));
clientSideScripts.RegisterClientScriptFile("jqDnR.js", CommonFunctions.FixupUrlWithoutSessionID("~/WebUI/Scripts/JGrid/js/jqDnR.js"));

基本上我觉得它一定是蠢事......但我现在无法弄明白......



1> 小智..:

在过去的几个小时里,我一直在努力解决同样的问题.我现在已经放弃了让AddJSONData工作 - 我的Web服务方法正在返回一个数组,所以看起来使用addRowData会起作用.

function ReceivedClientData(data) {
        var thegrid = $("#list4");
        for (var i = 0; i < data.length; i++) {
            thegrid.addRowData(i+1, data[i]);
        }
    }

推荐阅读
手机用户2502852037
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有