2012-10-25 144 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設置。