-2

我正在尝试将数据库中的数据绑定到 KendoUI Grid,但数据未显示...我正在从数据库中获取数据成功转换为序列化代码,但数据未显示在 Kendo Grid 中。请帮助我...

<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);

}
4

1 回答 1

1

我在您的代码中看到了很多问题:

  • dataType不能设置为“odata” 。尝试“json”。引用jQuery 文档

    默认值:智能猜测(xml、json、脚本或 html)

  • Kendo DataSourcetype也设置为“odata”,但您的页面显然不是 OData 服务。删除它。

  • 您正在设置jsonReaderKendo 数据源不支持的设置。我想您需要使用架构设置。

于 2012-10-26T07:10:59.733 回答