<script type="text/javascript">
$(document).ready(function () {
$("#jqGrid").jqGrid({
url: 'UserRoles.aspx/GetUserRoles',
datatype: 'json',
mtype: 'POST',
colNames: ["User Role Id", "User Role", "Description", "Status"],
colModel: [
{ name: 'UserRoleId', index: 'UserRoleId', jsonmap: 'UserRoleId', width: 75 },
{ name: 'UserRoleName', index: 'UserRoleName', jsonmap: 'UserRoleName', width: 150, editable: true },
{ name: 'UserRoleDescription', index: 'UserRoleDescription', jsonmap: 'UserRoleDescription', formatter: 'textarea', width: 150, editable: true },
{ name: 'UserRoleStatus', index: 'UserRoleStatus', jsonmap: 'UserRoleStatus', formatter: 'checkbox', align: 'center', width: 150, editable: true }
],
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
contentType: "application/json; charset=utf-8",
serializeGridData: function (postData) {
// extend the parameter which will be send to the server
//postData.formVars = $("#Content2").serializeArray();
// serialize the parameters as JSON string
return JSON.stringify(postData);
},
caption: "User Roles List",
viewrecords: true,
gridview: true,
autoencode: true,
loadonce: true,
loadError: function (xhr, st, err) {
alert("Type: " + st + "; Response: " + xhr.status + " " + xhr.statusText + err);
//jQuery("#rsperror").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText);
},
jsonReader: {
root: function (obj) { return obj.d; }, //array containing actual data
//page: function (obj) { return 1; },
//total: function (obj) { return obj.d.length/25; },
//records: function (obj) { return obj.d.length; }, //total number of records
repeatitems: false,
id: 'UserRoleId',
cell: '',
},
width: 780,
height: 250,
rowNum: 25,
rowList: [25, 50, 100],
pager: "#jqGridPager",
}).navGrid('#jqGridPager', { edit: true, add: true, del: true, excel: true, addtext: 'ADD' }, // Edit options
{
savekey: [true, 13],
reloadAfterSubmit: true,
jqModal: false,
closeOnEscape: true,
closeAfterEdit: true,
url: '../BibLOSApp/UserRoles.aspx/UpdateUserRole',
datatype: 'json',
mtype:'POST',
ajaxEditOptions: { contentType: 'application/json; charset=utf-8' },
contentType: "application/json; charset=utf-8",
serializeEditData: function (postData) {
// extend the parameter which will be send to the server
//postData.formVars = $("#Content2").serializeArray();
// serialize the parameters as JSON string
alert(JSON.stringify(postData));
return JSON.stringify(postData);
},
});
});
</script>
code behind
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string UpdateUserRole()
{
string s = "test";
return s;
}
我可以加载网格,但问题是在编辑数据时。我可以在编辑时单击提交时调用该方法。可以帮助我如何将json数据从jqgrid获取到web方法。
答案 0 :(得分:0)
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string UpdateUserRole(string UserRoleName, string UserRoleDescription, string UserRoleStatus, string id)
{
string s = "test";
return s;
}
我已经从我的json对象中删除了oper参数并传递了其余参数,并且它有效。