我正在尝试使用JQgrid并编辑我的对象。但是,我不知道如何将参数传递给服务器端代码。这是我的jq代码:
jQuery("#tblList").jqGrid({
url: 'CityList.aspx/GetList',
editurl: 'CityList.aspx/GetList',
mtype: 'POST',
datatype: 'json',
postData: { searchString: '', searchField: '', searchOper: '' },
ajaxGridOptions: { contentType: "application/json" },
serializeGridData: function (postData) {
var propertyName, propertyValue, dataToSend = {};
for (propertyName in postData) {
if (postData.hasOwnProperty(propertyName)) {
propertyValue = postData[propertyName];
if ($.isFunction(propertyValue)) {
dataToSend[propertyName] = propertyValue();
} else {
dataToSend[propertyName] = propertyValue
}
}
}
return JSON.stringify(dataToSend);
},
jsonReader: {
root: "d.rows",
page: "d.page",
total: "d.total",
records: "d.records"
},
colNames: ['Id', 'Şehir Adı'],
colModel: [
{ name: 'CityId', index: 'CityId', hidden: true },
{ name: 'Name', index: 'Name', width: 400, editable: true, edittype: 'text' }
],
ondblClickRow: function (id) { alert("You double click row with id: " + id); },
pager: '#tblPager',
rowList: [10, 20, 30],
sortname: 'CityId',
sortorder: 'desc',
rowNum: 10,
loadtext: "Yukleniyor....",
shrinkToFit: false,
multiselect: false,
emptyrecords: "Kayit Bulunamadi",
autowidth: true,
shrinkToFit: true,
height: "400",
rownumbers: true,
//subGrid: true,
caption: 'Şehirler'
}).navGrid('#tblPager', { add: true, edit: true, del: true, reload: true });
});
jQuery("#tblList").editGridRow(rowid, properties);
我是jqGrid的新手,你能告诉我如何编辑我的记录吗?
答案 0 :(得分:0)
我设置了DataRequesting事件:
在后面的代码中 -
public void JQGridVets_DataRequesting(object sender, JQGridDataRequestEventArgs e)
{
ObjectDataSourceVets.SelectParameters["BusID"].DefaultValue = e.ParentRowKey;
ObjectDataSourceVets.InsertParameters["BusID"].DefaultValue = e.ParentRowKey;
}
在aspx文件中 -
<asp:ObjectDataSource ID="ObjectDataSourceVets" runat="server"
SelectMethod="GetVetAll" TypeName="AHP.Data.PhoneBookRepository"
UpdateMethod="UpdateVet" InsertMethod="InsertVet"
OldValuesParameterFormatString="original_{0}" >
<InsertParameters>
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="M" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="vetphone" Type="String" />
<asp:Parameter Name="vetemail" Type="String" />
<asp:Parameter Name="Degree" Type="String" />
<asp:Parameter Name="License" Type="String" />
<asp:Parameter Name="Code" Type="String" />
<asp:Parameter Name="BusID" Type="String" />
<asp:Parameter Name="oper" Type="String" />
<asp:Parameter Name="id" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:Parameter Name="BusID" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="M" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="vetphone" Type="String" />
<asp:Parameter Name="vetemail" Type="String" />
<asp:Parameter Name="Degree" Type="String" />
<asp:Parameter Name="License" Type="String" />
<asp:Parameter Name="Code" Type="String" />
<asp:Parameter Name="VetID" Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>
所以在ObjectDataSource中指定的InsertMethod中,busid具有正确的值。
这用于从子网格添加子记录。