我是 jqGrid 的初学者,我想在 jqGrid 中实现删除肌动蛋白我写这个代码来填充 jqGrid
$(function () {
var grid = $('#list');
grid.jqGrid({
url: 'jQGridHandler.ashx',
postData: { ActionPage: 'TransportType', Action: 'Fill' },
ajaxGridOptions: { cache: false },
loadonce: true,
direction: "rtl",
datatype: 'json',
height: 490,
colNames: ['Code', 'TransportType', 'TransportTypeAbbr', 'Remark'],
colModel: [
{ name: 'TRANSPORT_ID', width: 100, sortable: true, editable: true },
{ name: 'TRANSPORT_NAME', width: 200, sortable: true, editable: true },
{ name: 'TRANSPORT_ABBR', width: 100, sortable: true, editable: true },
{ name: 'REMARK', width: 100, sortable: true, editable: true }
],
gridview: true,
rowNum: 20,
rowList: [20, 40, 60],
pager: '#pager',
sortname: 'TRANSPORT_ID',
viewrecords: true,
sortorder: 'ASC',
caption: '',
rownumbers: true
});
grid.jqGrid('navGrid', '#pager', { add: true, edit: true, del: true },
{ height: 300, width: 300, url: "JQGridHandler.ashx?ActionPage=TransportType&Action=Update", reloadAfterSubmit: false },
{ height: 400, width: 500, url: "JQGridHandler.ashx?ActionPage=TransportType&Action=Insert", reloadAfterSubmit: false },
{ url: "JQGridHandler.ashx?ActionPage=TransportType&Action=Delete", reloadAfterSubmit: false },
{ multipleSearch: true, overlay: false, width: 460 });
在 jQGridHandler 我写这段代码
case "TransportType":
var transport = new TransportTypesBusiness();
TRANSPORT_TYPES transportItem;
switch (request.QueryString["Action"])
{
case "Fill":
string numberOfRows = request["rows"];
string pageIndex = request["page"];
int totalRecords = 0;
output = transport.BuildJQGridResults(Int32.Parse(numberOfRows), Int32.Parse(pageIndex), totalRecords);
response.Write(output);
break;
case "FillDrop":
output = transport.BuildJQGridResults();
response.Write(output);
break;
case "Insert":
transportItem = new TRANSPORT_TYPES {
TRANSPORT_NAME = request["TRANSPORT_NAME"].ToString(),
TRANSPORT_ABBR = request["TRANSPORT_ABBR"].ToString(),
REMARK = request["REMARK"].ToString()
};
bool isInsert = transport.AddNew(transportItem);
break;
case "Update":
transportItem = new TRANSPORT_TYPES {
TRANSPORT_ID = int.Parse(request["TRANSPORT_ID"].ToString()),
TRANSPORT_NAME = request["TRANSPORT_NAME"].ToString(),
TRANSPORT_ABBR = request["TRANSPORT_ABBR"].ToString(),
REMARK = request["REMARK"].ToString()
};
bool isUpdate = transport.Update(transportItem);
break;
case "Delete":
bool isDelete =
transport.Delete(
transport.Find(c => c.TRANSPORT_ID == int.Parse(request["TRANSPORT_ID"].ToString())));
break;
}
什么时候删除记录,我无法获得request["TRANSPORT_ID"].ToString()
价值。
请帮我。谢谢大家
编辑 1:我从这里编辑脚本
$(function () {
var grid = $('#list');
grid.jqGrid({
url: 'jQGridHandler.ashx',
postData: { ActionPage: 'TransportType', Action: 'Fill' },
ajaxGridOptions: { cache: false },
loadonce: true,
direction: "rtl",
datatype: 'json',
height: 490,
colNames: ['Code', 'TransportType', 'TransportTypeAbbr', 'Remark'],
colModel: [
{ name: 'TRANSPORT_ID', key: true,,hidden:true, editable:false },
{ name: 'TRANSPORT_NAME', width: 200, sortable: true, editable: true },
{ name: 'TRANSPORT_ABBR', width: 100, sortable: true, editable: true },
{ name: 'REMARK', width: 100, sortable: true, editable: true }
],
cmTemplate: { width: 100, editable: true },
prmNames: { oper: 'Action', editoper: 'Update', addoper: 'Insert',
deloper: 'Delete', id: 'STATUS_ID'
},
gridview: true,
rowNum: 20,
rowList: [20, 40, 60],
pager: '#pager',
sortname: 'TRANSPORT_ID',
viewrecords: true,
sortorder: 'ASC',
caption: '',
rownumbers: true
});
$.extend($.jgrid.edit, {
editData: { ActionPage: 'StatusType' },
savekey: [true, 13],
closeOnEscape: true,
closeAfterEdit: true,
closeAfterAdd: true,
reloadAfterSubmit: false,
recreateForm: true
});
grid.jqGrid('navGrid', '#pager', { add: true, edit: true, del: true },
{ height: 300, width: 300 },
{ height: 400, width: 500 },
{},
{ width: 460 });
并在处理程序中获取
ActionPage 写这段代码
HttpRequest request = context.Request;
string ss = request["ActionPage"].ToString();
网格首先加载数据,但单击编辑按钮时出现错误。