0

当我编辑行并按 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;
}
4

1 回答 1

0

在 colModel BOTH key:true 和 editable:true 需要设置。

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

于 2013-12-12T05:39:00.037 回答