【发布时间】:2016-04-21 06:30:21
【问题描述】:
JQ Grid 没有加载到 Visual Studio 2013,但它在 Visual Studio 2010 中运行良好。当我在浏览器中按 F12 时出现以下错误:
Uncaught TypeError: Cannot read property 'length' of undefined
以下脚本适用于 Visual Studio 2010 和 2008。
下面是我的 HTML 代码:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<link href="JQGridReq/jquery-ui-1.9.2.custom.css" rel="stylesheet" type="text/css" />
<link href="JQGridReq/ui.jqgrid.css" rel="stylesheet" type="text/css" />
<script src="JQGridReq/jquery-1.9.0.min.js" type="text/javascript"></script>
<script src="JQGridReq/jquery.jqGrid.js" type="text/javascript"></script>
<script src="JQGridReq/grid.locale-en.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#dataGrid").jqGrid({
url: '<%=ResolveUrl("Default5.aspx/GetDataFromDB") %>',
datatype: 'json',
mtype: 'POST',
serializeGridData: function (postData) {
return JSON.stringify(postData);
},
ajaxGridOptions: { contentType: "application/json" },
loadonce: true,
//toolbar: [true, "top"],
colNames: ['Emp_ID', 'Name', 'Designation', 'City', 'State', 'Country'],
colModel: [
{ name: 'Emp_ID', index: 'Emp_ID', width: 150, stype: 'text' },
{ name: 'Name', index: 'Name', width: 150, stype: 'text', sortable: true, editable: true },
{ name: 'Designation', index: 'Designation', width: 150, editable: true },
{ name: 'City', index: 'City', width: 150, editable: true },
{ name: 'State', index: 'State', width: 150, align: "right", editable: true },
{ name: 'Country', index: 'Country', width: 150, align: "right", editable: true },
],
multiselect: true,
multipleSearch: true,
pager: '#pager',
rowNum: 10,
rowList: [10, 20, 30],
viewrecords: true,
gridview: true,
jsonReader: {
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.d.length; },
root: function (obj) { return obj.d; },
repeatitems: false,
id: "0"
},
caption: 'Employee details'
}).navGrid('#pager', { search: true, edit: false, add: false, del: false, searchtext: "Search" });
jQuery("#dataGrid").jqGrid('navGrid', "#pager", {}, {}, {}, {},
{
multipleSearch: true, closeAfterSearch: true, closeAfterReset: true,
onClose: function () {
//do work
return true; // return true to close the search grid
}
});
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="">
<tr>
<td style="padding-left: 20px; padding-top: 20px; padding-bottom: 20px; background-color: skyblue; font-family: 'Times New Roman'; font-weight: bold; font-size: 20pt; color: chocolate;"></td>
</tr>
<tr>
<td style="text-align: center; vertical-align: central; padding: 50px;">
<table id="dataGrid" style="text-align: center;"> </table>
<div id="pager"></div>
</td>
</tr>
</table>
</div>
</form>
【问题讨论】:
-
将
jquery-1.9.0.min.js文件放在jqGrid.js之前 -
我的地方,但又是一样的: .@KartikeyaKhosla
标签: javascript c# jquery visual-studio-2013 jqgrid-asp.net