网格没有显示任何值,我可以看到代码隐藏文件中打印的 JSON 值。请找到下面列出的 JS 代码和 CodeBehind -
$(document).ready(function () {
alert("Page Load1");
createUserGrid();
alert("Page Load2");
});
function createUserGrid() {
alert("call webservice");
$("#tblJQGrid").jqGrid({
url: '/POWeb.asmx/GetPOCores?strPoNo=411101',
datatype: 'json',
mtype: 'GET',
loadonce: true,
gridview: true,
autoencode: true,
height:"auto",
colNames: ['Number', 'Name', 'Notes'],
colModel: [
{ name: 'id', index: 'id', width: 60, editable: true, editoptions: { readonly: true }, sorttype: "string" },
{ name: 'name', index: 'name', width: 100, sorttype: "string", editable: true },
{ name: 'note', index: 'note', width: 150, sortable: false, editable: true }
],
jsonReader: {
repeatitems: false,
root: function (obj) { return obj.d; }
},
ajaxGridOptions: { contentType: "application/json; charset=utf-8" },
rowNum: 1,
rowList: [1, 2, 3],
pager: '#divPager',
editurl: 'SaveEdit.aspx',
caption: "Users Data",
serializeGridData: function (postData) {
return JSON.stringify(postData);
}
});
}
</script>
下面是我的 CodeBehind 文件
namespace MenuCheck
{
/// <summary>
/// Summary description for POWeb
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class POWeb : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public List<POItems> GetPOCores(string strPoNo)
{
//string strPoNo = "411101";
System.Diagnostics.Debug.WriteLine(" In Web Method");
List<POItems> result = null;
DB dbobj = new DB();
result = dbobj.getPOItems(strPoNo, 0);
return result;
}
}