jqGrid的addJSONData + ASP.NET 2.0 WS [英] JqGrid addJSONData + ASP.NET 2.0 WS

查看:142
本文介绍了jqGrid的addJSONData + ASP.NET 2.0 WS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是有点失落。我试图实现基于jqGrid的一个解决方案,并试图使用功能的数据类型。我的书,我想所有设置好的,我得到WS调用,并得到JSON回来,我得到了客户方更迭的ajax调用和我绑定的jqGrid使用 addJSONData ,但格保留为空。我没有任何线索,现在也...在同一个页面等本土的样品就没有这个问题(jsonstring ...)

我的WS方法如下:

  [的WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)
        公共字符串GetGridData()
         {
             //加载列表
             InitSessionVariables();
             SA.DB.DenarnaEnota.DenarnaEnotaDB DB =新SAOP.SA.DB.DenarnaEnota.DenarnaEnotaDB();
             DataSet的DS = db.GetLookupForDenarnaEnota(SAOP.FW.DB.RecordStatus.All);             //开启成HTML格式友好
             GetGridData summaryList =新GetGridData();             summaryList.page =1;
             summaryList.total =10;
             summaryList.records =160;
             INT I = 0;
             的foreach(在ds.Tables的DataRow博士[0] .Rows)
             {
                 GridRows行=新GridRows();
                 row.id =博士[DenarnaEnotaID]的ToString()。
                 row.cell =[+\\+博士[DenarnaEnotaID]。的ToString()+\\
                                       +,+\\+ DR [Kratica]。的ToString()+\\
                                       +,+\\+ DR [Naziv]。的ToString()+\\
                                       +,+\\+ DR [Sifra]。的ToString()+\\                          +];
                 summaryList.rows.Add(行);
             }
             返回JsonConvert.SerializeObject(summaryList);         }

我ASCX code是这样的:

 的jQuery(文件)。就绪(函数(){
jQuery的(#清单)。jqGrid的({
                        数据类型:功能(POSTDATA){jQuery.ajax({URL:../../ AjaxWS / TemeljnicaEdit.asmx / GetGridData',
                                                                       数据:'{}',
                                                                       数据类型:JSON,
                                                                       输入:POST,
                                                                       的contentType:应用/ JSON的;字符集= UTF-8,
                                                                       完成:功能(jsondata,STAT){
                                                                                                         如果(STAT ==成功)
                                                                                                         {
                                                                                                              VAR clearJson = jsondata.responseText;                                                                                                              VAR thegrid =的jQuery(#清单)[0];
                                                                                                              变种myjsongrid =的eval('('+ clearJson +')');
                                                                                                              ALFS
                                                                                                              thegrid.addJSONData(myjsongrid.replace(/ \\\\ / g时,''));
                                                                                                         }
                                                                                                        }
                                                                     }
                                                                    );
                                                       },
                        colNames:['DenarnaEnotaID','Kratica','Sifra','Naziv'],
                        colModel:
                                   {名称:'DenarnaEnotaID',索引:DenarnaEnotaID',宽度:100},
                                   {名称:'Kratica',索引:Kratica',宽度:100},
                                   {名称:'Sifra',索引:Sifra',宽度:100},
                                   {名称:'Naziv',索引:Naziv',宽度:100}],                        的rowNum:15,
                        rowList:[15,30,100]
                        寻呼机:jQuery的('#寻呼机),
                        sortname:'ID',
                      // loadtext:Nalagam zapise ......
                       // viewrecords:真实,
                        排序顺序:递减,
                       //说明:Vrstice
                       //宽:800,
                        imgpath:../Scripts/JGrid/themes/basic/images});               });

从WS我得到JSON是这样的:

<$p$p><$c$c>{page:1″,total:10″,records:160″,rows:[{\"id\":\"18\",\"cell\":\"[\"18\",\"BAM\",\"Konvertibilna马卡,977]},{ID:19,细胞:[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,细胞:..................[13,PLN,Po​​ljski zlot,985]},{id为:14,小区:[14,SEK,Švedska克朗, 752]},{ID:15,细胞:[15,SKK,Slovaška克朗,703]},{ID:16, 小区:[16,美元,AmeriškiDOLAR,840]},{id为:17,小区:[17,XXX, Nobena币值,000]},{id为:1,小区:[1,坐,斯洛文托拉尔,705]}]}

我已经注册该JavaScript:

  clientSideScripts.RegisterClientScriptFile(的prototype.js,CommonFunctions.FixupUrlWithoutSessionID(〜/ WebUI中/脚本/原型1.6.0.2.js));clientSideScripts.RegisterClientScriptFile(jquery.js和CommonFunctions.FixupUrlWithoutSessionID(〜/ WebUI中/脚本/ JGrid / jquery.js和));
clientSideScripts.RegisterClientScriptFile(jquery.jqGrid.js,CommonFunctions.FixupUrlWithoutSessionID(〜/ WebUI中/脚本/ JGrid / jquery.jqGrid.js));
clientSideScripts.RegisterClientScriptFile(jqModal.js,CommonFunctions.FixupUrlWithoutSessionID(〜/ WebUI中/脚本/ JGrid / JS / jqModal.js));
clientSideScripts.RegisterClientScriptFile(jqDnR.js,CommonFunctions.FixupUrlWithoutSessionID(〜/ WebUI中/脚本/ JGrid / JS / jqDnR.js));

基本上,我想它一定是愚蠢的东西......但现在我不出来...


解决方案

我一直在试图解决同样的问题在过去的几个小时。现在我已经放弃了让AddJSONData工作 - 所以它看起来像使用addRowData将工作我的web服务方法返回一个数组

 函数ReceivedClientData(数据){
        VAR thegrid = $(#list4);
        对于(VAR I = 0; I&LT; data.length;我++){
            thegrid.addRowData第(i + 1,数据[I]);
        }
    }

I am a bit lost. I've tried to implement a solution based on JqGrid and tried to use function as datatype. I've setted all by the book I guess, I get WS invoked and get JSON back, I got succes on clientside in ajax call and I "bind" jqGrid using addJSONData but grid remains empty. I do not have any clue now... other "local" samples on same pages works without a problem (jsonstring ...)

My WS method looks like:

[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);

         }

my ASCX code is this:

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"}); 

               });

from WS I get JSON like this:

{"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"]"}]}

I have registered this 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"));

Basically I think it must be something stupid... but I can't figure it out now...

解决方案

I've been trying to solve the same problem for the last couple of hours. I've now given up on getting AddJSONData working - my web service method is returning an array so it looks like using addRowData will work.

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

这篇关于jqGrid的addJSONData + ASP.NET 2.0 WS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆