单击jqGrid中的行时填充下拉列表中的错误

单击jqGrid中的行时填充下拉列表中的错误,jqgrid,jqgrid-asp.net,Jqgrid,Jqgrid Asp.net,我想在单击行时填充jqGrid单元格下拉列表。我正在单击行,但dropdownlist没有填充 我编写的用于在编辑或单击行时填充dropdownlist的代码是: colModel: [ { name: 'Emp_code', width: 50, sortable: false, align: "center" }, { name: 'Emp_name', width: 200, sortable: false }, //{ na

我想在单击行时填充jqGrid单元格下拉列表。我正在单击行,但dropdownlist没有填充

我编写的用于在编辑或单击行时填充dropdownlist的代码是:

colModel: [
            { name: 'Emp_code', width: 50, sortable: false, align: "center" },
            { name: 'Emp_name', width: 200, sortable: false },
        //{ name: 'totalhours', width: 100, sortable: false, align: 'center', editable: true, edittype: "select", editoptions: { value: "1:1;2:2;3:3;4:4;5:5;6:6;7:7;8:8;9:9"} }
            {name: 'totalhours', index: 'totalhours', width: 100, sortable: false, align: 'center', editable: true, edittype: "select",
            editoptions:
            {
                dataInit: function(elem) {

                    $(elem).empty()
                    .append($('<option></option>').val("1").html("Apples"))
                    .append($('<option></option>').val("2").html("Oranges"));

                }
            }
        }
        ],
colModel:[
{name:'Emp_code',宽度:50,可排序:false,对齐:“center”},
{name:'Emp_name',宽度:200,可排序:false},
//{name:'totalhours',width:100,sortable:false,align:'center',edit:true,edittype:'select',editoptions:{value:'1:1;2:2;3:3;4:4;5:5;6:6;7:7;8:8;9'}
{name:'totalhours',index:'totalhours',width:100,sortable:false,align:'center',editable:true,edittype:'select',
编辑选项:
{
dataInit:函数(elem){
$(elem).empty()
.append($('').val(“1”).html(“苹果”))
.append($('').val(“2”).html(“橙子”);
}
}
}
],

我想在单击行时填充totalhours列,该列将填充apple和oranges,但不知怎的,我得到的是空白下拉列表。在行单击时,将显示下拉列表,但未填充。

如果需要从服务器获取选择选项项,则应使用
dataUrl
和可选的
buildSelect
。如果服务器返回JSON而不是HTML片段,如

<select><option value="1">Apples</option><option value="2">Oranges</option></select>
applesorges
可以使用
buildSelect
将服务器响应转换为格式。如果srever返回JSON格式的字符串,则
buildSelect
事件处理程序的实现可以将JSON字符串转换为对象,然后从对象构造字符串


例如,您可以找到相应的代码示例。

根据您的建议,我这样做了

 colModel: [
            { name: 'Emp_code', width: 50, sortable: false, align: "center" },
            { name: 'Emp_name', width: 200, sortable: false },
        //{ name: 'totalhours', width: 100, sortable: false, align: 'center', editable: true, edittype: "select", editoptions: { value: "1:1;2:2;3:3;4:4;5:5;6:6;7:7;8:8;9:9"} }

           {name: 'totalhours', width: 100, sortable: false, align: 'center', editable: true, edittype: "select",
           editoptions: { dataUrl: '../Services/ServiceTest.asmx/GetListHours',
               buildSelect: function(data) {
                   alert('hello i am here ');
                   var response = jQuery.parseJSON(data.responseText);
                   var s = '<select>';
                   if (response && response.length) {
                       for (var i = 0, l = response.length; i < l; i++) {
                           var ri = response[i];
                           s += '<option value="' + ri + '">' + ri + '</option>';
                       }
                   }
                   return s + "</select>";
               }

           }
       }
        ],
colModel:[
{name:'Emp_code',宽度:50,可排序:false,对齐:“center”},
{name:'Emp_name',宽度:200,可排序:false},
//{name:'totalhours',width:100,sortable:false,align:'center',edit:true,edittype:'select',editoptions:{value:'1:1;2:2;3:3;4:4;5:5;6:6;7:7;8:8;9'}
{name:'totalhours',width:100,sortable:false,align:'center',editable:true,edittype:'select',
editoptions:{dataUrl:'../Services/ServiceTest.asmx/GetListHours',
buildSelect:函数(数据){
警惕(“你好,我在这里”);
var response=jQuery.parseJSON(data.responseText);
var s='';
if(响应和响应长度){
对于(变量i=0,l=response.length;i
我呼吁的相应网站是:

public String GetListHours() 
    {
        List<int> list = new List<int> { };            
        for (int i = 0; i < 10; i++)
        {
            list.Add(i);
        }
        return JsonConvert.SerializeObject(list);
    }
公共字符串GetListHours()
{
列表=新列表{};
对于(int i=0;i<10;i++)
{
列表.添加(i);
}
返回JsonConvert.SerializeObject(列表);
}

但当我点击该行时,下拉列表仍然显示为空白。。。是否有任何事件需要我进行校准?当我单击一行时应该被激发?要填充dropdownlist?以上是我根据你的建议试图实现的代码。但它似乎甚至没有调用dataurl来填充,因为函数警报根本没有启动

为什么不使用
editoptions:value
(请参阅)?当您在“单击行”上写下您需要的下拉列表时,您的意思是什么?您是使用单元格编辑模式还是在选择行上实现内联编辑?通常在
dataInit
中,不应覆盖单元格contain的contain。如果你需要自定义编辑控制,你应该使用这个:嗯,我是这个论坛的新手。。。所以还不习惯按钮和界面。。。。。当然,如果我得到ans,我会接受它。。。如果在任何地方我都没有这样做。。。对不起,这不是故意的。。。问题是。。这只是虚拟数据,我将实际实现从webservice返回的json。。。但不幸的是,这不仅是有效的。。。因此,我将如何从webservice本身(这是实际想法)放置json主要想法是原始内容将保持原样。。。但是当我单击行时。。它将进入编辑模式。。。dropdownlist会将json(或者非静态的项目列表..它必须是动态的)加载到dropdownlist中。。上面的代码只是为了测试。。。如果下拉列表正在填充或未填充。。。。当我点击jqGrid时,我已经发布了我的代码片段。你建议的。但是仍然没有结果。。不确定是什么原因导致ittry查看有关Fiddler(请参阅)或Firebug(请参阅)的服务器响应。我假设您的web服务的当前实现在SOAP XML中发送JSON字符串。您应该使用ASMX、WCF并将相应的属性放置在
ResponseFormat=ResponseFormat.Json
中。有关更多信息,请参阅。