我制作了一个小程序来使用 ExtJs 和 .NET webservice 方法填充 gridPanel,但它没有填充..我的代码如下
//这是我的网络服务方法
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true, XmlSerializeString = false)]
public List<Student> GetStudentList()
{
List<Student> obList = new List<Student>();
obList.Add(new Student(1, "John", "Doe"));
obList.Add(new Student(2, "Michael", "Crowd"));
obList.Add(new Student(3, "Gunnar", "Rasmundsson"));
obList.Add(new Student(4, "Alicia", "Mankind"));
return obList;
}
public class Student
{
private int _stid;
private string _stname;
private string _stservice;
public Student(){}
public Student(int stid, string stname, string stservice)
{
this.StId = stid;
this.StName = stname;
this.StService = stservice;
}
public int StId {
get { return this._stid; }
set { this._stid = value; }
}
public string StName {
get{return this._stname;}
set { this._stname = value; }
}
public string StService { get { return this._stservice; } set { this._stservice = value; } }
}
//这是我的 ExtJs 网格填充代码
Ext.onReady(function () {
var myStore = new Ext.data.JsonStore({
// Load data at once
autoLoad: true,
// Override default http proxy settings
proxy: new Ext.data.HttpProxy({
// Call web service method using GET syntax
url: 'GetStudent.asmx/GetStudentList',
// Ask for Json response
headers: { 'Content-type': 'application/json' }
}),
// Root variable
root: 'd',
// Record identifier
id: 'StId',
//reader:Jreader,
// Fields declaration
fields: ['StId', 'StName', 'StService'],
});
var grid = new Ext.grid.GridPanel({
// Set store
store: myStore,
// Columns definition
columns: [
{ dataIndex: 'StId', header: 'St Id' },
{ dataIndex: 'StName', header: 'St Name' },
{ dataIndex: 'StService', header: 'St Service' }
],
// Render grid to dom element with id set to panel
renderTo: 'divGrid',
width: 422,
height: 300
});
});
我也包括了
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/GetStudent.asmx" />
</Services>
</asp:ScriptManager>
<div id="divGrid"></div>
</form>
</body>
请让我知道我错在哪里,谢谢您的帮助!!!!