2013-03-18 22 views
2

我正在使用jQuery EasyUI CRUD數據網格在c#asp.net中開發一個網站。 但我需要用我的web服務替換.php文件來綁定datagrid,如下面的代碼片段。請告訴我一種方法。如何在jQuery EasyUI中綁定Web服務CRUD DataGrid

<table id="dg" title="My Users" style="width:700px;height:250px" 
      toolbar="#toolbar" pagination="true" idField="id" 
      rownumbers="true" fitColumns="true" singleSelect="true"> 
     <thead> 
      <tr> 
       <th field="firstname" width="50" editor="{type:'validatebox',options:{required:true}}">First Name</th> 
       <th field="lastname" width="50" editor="{type:'validatebox',options:{required:true}}">Last Name</th> 
       <th field="phone" width="50" editor="text">Phone</th> 
       <th field="email" width="50" editor="{type:'validatebox',options:{validType:'email'}}">Email</th> 
      </tr> 
     </thead> 
    </table> 

<script type="text/javascript"> 
     $(function(){ 
      $('#dg').edatagrid({ 
       url: 'get_users.php', 
       saveUrl: 'save_user.php', 
       updateUrl: 'update_user.php', 
       destroyUrl: 'destroy_user.php' 
      }); 
     }); 
    </script> 

回答

1

您可以使用jQuery Ajax和jTemplate。

$.ajax({ 
    url: "Your webservice path", 
    type: "POST", 
    data: "JSON formated data to pass in the webservice", 
    contentType: "application/json; charset=utf-8", 
    dataType: "json", 
    cache: false, 
    success: function (data) { 
     //You can further use jTemplate to output the data. 
    }, 
    error: function (data) { 
    } 
}); 

下面鏈路示出了用於jTemplate一個簡單的例子: http://www.codeproject.com/Articles/45759/jQuery-jTemplates-Grid