方法駐留ASPX頁面內:的jqGrid與asp.net [的WebMethod]內aspx頁面版本
$("#list").jqGrid({
url: 'DirStructure.aspx/getData', //Not able get any data from here saw in firebug reponse is page itself instead of JSON data.
datatype: 'json',
mtype: 'POST',
colNames: ['pkLanguageID', 'Language'],
colModel: [
{ name: 'pkLanguageID', index: 'pkLanguageID', width: 30, align: 'left', stype: 'text', editable: false },
{ name: 'Language', index: 'Language', width: 80, align: 'left', stype: 'text', editable: true}],
rowNum: 5,
rowList: [10, 20, 30],
pager: '#pager',
sortname: 'pkLanguageID',
sortorder: 'desc',
caption: "Test Grid",
viewrecords: true,
async: false,
loadonce: true,
gridview: true,
width: 500,
loadComplete: function (result) {
alert(jQuery("#list").jqGrid('getGridParam', 'records'));
},
loadError: function (xhr) {
alert("The Status code:" + xhr.status + " Message:" + xhr.statusText);
}
});
方法駐留內DirStructure.aspx(寫的WebMethod):
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string getData()
{
System.Web.Script.Serialization.JavaScriptSerializer serializer = new
System.Web.Script.Serialization.JavaScriptSerializer();
DataSet dsLang = new DataSet();
dsLang = CommonCode.CommonCode.GetIndividualLanguageList(7, 350027);
System.Diagnostics.Debug.Write(dsLang.GetXml());// Dataset for languages.
DataTable dt = dsLang.Tables[0];
System.Diagnostics.Debug.Write(GetJson(dt));
return GetJson(dt);
}
public static string GetJson(DataTable dt)
{
System.Web.Script.Serialization.JavaScriptSerializer serializer = new
System.Web.Script.Serialization.JavaScriptSerializer();
List<Dictionary<string, object>> rows =
new List<Dictionary<string, object>>();
Dictionary<string, object> row = null;
foreach (DataRow dr in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
row.Add(col.ColumnName.Trim(), dr[col]);
}
rows.Add(row);
}
return serializer.Serialize(rows);
}
我degugged此我我能夠在方法內部獲取JSON數據,但無法在jqgrid中查看。 請幫我一把。
http://stackoverflow.com/questions/25304099/如何使用數據表從code-behind-in-jqxgrid?answertab = votes#tab-top –