jqGrid编辑行向web方法发送行号而不是id

时间:2013-08-17 09:14:37

标签: jqgrid

当我编辑行并按Enter键将数据发送到Web方法时,它会发送一个行号而不是id(例如,而不是id = 111,它发送'3'表示网格上的第3行)。我如何获得id值?

这是代码:

    $(document).ready(function () { 
        var id;
        var lastsel;
        jQuery("#rowed3").jqGrid({
            url:'Default3.aspx/GetData',
            datatype: "xml",
            ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
            ajaxRowOptions: { contentType: 'application/json; charset=utf-8' },
            serializeGridData: function (postData) {
                return JSON.stringify(postData);
            },
            serializeRowData: function (postData) {
                return JSON.stringify(postData);
            },
            mtype:'GET',
            xmlReader: {
                root: "programs",
                row: "program",
                repeatitems: false
            },
            colNames:['id','field1','field2'],
            colModel:[
                { name: 'id', index: 'id', width: 55, hidden: false, editable: false, editrules: { edithidden: false }, hidedlg: true },
                { name: 'field1', index: 'field1', width: 90, editable: true },
                { name: 'field2', index: 'field2', width: 100, editable: true }
            ],
            rowNum:10,
            rowList:[10,20,30],
            pager: '#prowed3',
            sortname: 'id',
            viewrecords: true,
            sortorder: "desc",
            onSelectRow: function(id){
                if(id && id!==lastsel){
                    jQuery('#rowed3').jqGrid('restoreRow',lastsel);
                    jQuery('#rowed3').jqGrid('editRow',id,true);
                    lastsel=id;
                }
                //$("#rowed3").jqGrid('setGridParam', { editurl: 'Default3.aspx/EditRow' });
            },
            onCellSelect: function(rowid,iCol,cellcontent,e) {
                alert(cellcontent);},
            //ondblClickRow: function(rowid) {
            //    jQuery('#rowed3').jqGrid('editRow',id,true);
            //},
            editurl: "Default3.aspx/EditRow",
            caption: "Using events example"
        });
        jQuery("#rowed3").jqGrid('navGrid',"#prowed3",{edit:false,add:false,del:false});
    });



[WebMethod]
//[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)]
public static string EditRow(string id,string field1,string field2)
{

    string x = id; ;


    return x;
}

1 个答案:

答案 0 :(得分:0)

在colModel中有两个键:true和editable:需要设置true。

我认为我隐藏的ID字段的可编辑性是相关的,因此原始评论不能正常工作