我正在尝试将json格式的数据绑定到Jqgrid。这是一个简单的网站应用程序。我已经尝试过自定义表。现在我想使用jqgrid绑定它。 .aspx或脚本代码如下:
<script src="JS/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
url: "JQGridBindData.aspx/GetAllDetails",
data:{},
type: "POST",
contentType: "application/json; charset=utf-8",
datatype: "json",
success: function (result) {
var data = JSON.parse(result.d);
var array = data.Table;
colNames: ['Country_Code', 'Country', 'ISD_Code']
colModel: [
{name: 'Country_Code', index: 'Country_Code', width: 60, sorttype: "int"},
{name: 'Country', index: 'Country', width: 60, sorttype: "string"},
{name: 'ISD_Code', index: 'ISD_Code', width: 60, sorttype: "string"}
]
},
multiselect: true,
rowNum: 10,
rowList: [5, 10, 20, 50, 100],
pager: jQuery('#pager1'),
sortorder: "desc",
viewrecords: true,
caption: "Manipulating Array Data",
error: function (){
alert(JSON.stringify(Error));
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<table id="jQGridDemo">
</table>
<div id="jQGridDemoPager">
</div>
<br />
<br />
</form>
在我的.cs页面中,我得到的是这样的值。我的.cs边码是
[WebMethod]
public static string GetAllDetails()
{
Generic gn = new Generic();
DataSet ds = gn.ExecuteDataset("Country_master_view", 0);
string data = JsonConvert.SerializeObject(ds,Formatting.Indented);
return data;
}