我正在尝试将数据从数据库绑定到KendoUI网格但数据未显示...我从数据库中获取数据成功转换为序列化代码但数据未显示在Kendo Grid中.. plz帮助我..
<div id="example" class="k-content">
<div id="grid"></div>
<script type="text/javascript">
$(document).ready(function(){
$("#grid").kendoGrid({
dataSource:
{
type:"odata",
serverPaging: true,
serverSorting:true,
pageSize:100,
transport:
{
read:
{
url:"Fetchdata.aspx",
contentType: "application/json;charset=utf-8",
dataType: "odata",
jsonReader:
{
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false
}
}
}
},
height:100,
scrollable:
{
virtual: true
},
sortable: true,
columns: [
"dptId",
{ title: "Name", field: "dptName" },
{ title: "Description", field: "dptdescription" }
]
});
});
</script>
</div>
protected void Page_Load(object sender,EventArgs e) {
Response.Write(GetData());
Response.End();
}
protected string GetData()
{
EmployeeBM empbm = new EmployeeBM();
List < Departement> list= new List<Departement>();
list = empbm.BindDepartment();
return GridData(1, 1,list.Count, list);
}
public string GridData(int noOfPages, int startPage, int noOfRecords, List<Departement> list)
{
var gridData = new
{
total = noOfPages,
page = startPage,
records = noOfRecords,
rows = list,
};
var jsonSerializer = new JavaScriptSerializer();
return jsonSerializer.Serialize(gridData);
}
答案 0 :(得分:1)
我在您的代码中看到了很多问题:
dataType
无法设为“odata”。试试“json”。引用jQuery documentation:
默认值:智能猜测(xml,json,script或html)
Kendo DataSource type
也设置为“odata”,但您的网页显然不是OData服务。删除它。
您正在设置Kendo DataSource不支持的jsonReader
。我想您需要使用schema设置。