2012-10-25 73 views
-2

我想将数据从数据库绑定到KendoUI Grid,但数据没有显示出来...我从数据库中获取数据,成功转换为序列化代码,但数据不显示在Kendo Grid中.. plz帮助我...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> 

保护无效的Page_Load(对象发件人,EventArgs的){

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

} 

回答

1

我看到你的代码不少问题:

  • dataType不能设置为“odata”。尝试“json”。引述jQuery documentation

    默认:智能猜测(XML,JSON,脚本或HTML)

  • 剑道的DataSource type也被设置为 “OData的”,但网页显然不是一个OData服务。删除。

  • 您正在设置 Kendo数据源不支持。我想你需要使用schema设置。