gpt4 book ai didi

asp.net - jqgrid 添加行并将数据发送到 webservice 进行插入

转载 作者:行者123 更新时间:2023-12-01 01:04:46 25 4
gpt4 key购买 nike

我已经能够使用 jQuery/Ajax 将数据从 Web 服务中提取到 jQGrid 中。现在我想将添加/编辑的数据发送回网络服务。我已经看到一些使用 PHP 和 editurl: 命令的示例。这也适用于网络服务(就像我最初提取数据的方式一样)吗?

我已经多次查看这些示例。我什至找到了another question这与我要问的类似,但是我无法找到任何真实的例子来说明如何做我需要的事情。存在吗?

:更新:

jQuery(document).ready(function () {
jQuery("#list").jqGrid({
datatype: processrequest,
mtype: 'POST',
jsonReader: {
root: "ListExercise", //arry containing actual data
page: "Page", //current page
total: "Total", //total pages for the query
records: "Records", //total number of records
repeatitems: false,
id: "ID" //index of the column with the PK in it
},
colNames: ['Id', 'Exercise'],
colModel: [
{ name: 'exercise_id', index: 'exercise_id',editable:false },
{ name: 'exercise_value', index: 'exercise_value',editable:true }
],
caption: 'MyFitnessApplication',
pager: '#pager',
rowNum: 10,
rowList: [10, 20, 30],
sortorder: "desc",
viewrecords: true,
height: '250px',
loadonce: true,
editurl: "../webService/exercise_ws.asmx/insertRecord"
}).navGrid('#pager', { edit: true, add: true, del: false });
});

如您所见,我添加了 editurl 标签。这似乎确实调用了我的网络服务。现在我不知道如何将实际参数传递给网络服务。我遗漏了一些东西,非常感谢您的帮助!

最佳答案

首先,您可以更改用于添加/编辑的一些默认选项:

jQuery.extend(jQuery.jgrid.edit, {
ajaxEditOptions: { contentType: "application/json" },
recreateForm: true,
serializeEditData: function (postData) {
if (postData.exercise_value === undefined) { postData.exercise_value = null; }
return JSON.stringify(postData);
}
});

(其中 JSON.stringifyhttp://www.json.org/js.html 中定义的函数)。然后将发送到服务器的数据进行 JSON 编码。几乎相同的设置可用于删除

jQuery.extend(jQuery.jgrid.del, {
ajaxDelOptions: { contentType: "application/json" },
serializeDelData: function (postData) {
if (postData.exercise_value === undefined) { postData.exercise_value = null; }
return JSON.stringify(postData);
}
});

现在您可以像下面一样定义insertRecord

[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public int ModifyData (string exercise_value, string oper, string id)
{
if (String.Compare (id, "_empty", StringComparison.Ordinal) == 0 ||
String.Compare (oper, "add", StringComparison.Ordinal) == 0) {

// TODO: add new item with the exercise_value and return new id
// as the method result
}
else if (String.Compare (oper, "edit", StringComparison.Ordinal) == 0) {
// TODO: modify the data identified by the id
}
else if (String.Compare (oper, "del", StringComparison.Ordinal) == 0) {
// TODO: delete the data identified by the id
}
}

您没有写出哪种类型具有exercise_id:整数或字符串。如果您使用字符串 ids,上面的代码应该稍微改变一下。

关于asp.net - jqgrid 添加行并将数据发送到 webservice 进行插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3917102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com