2013-02-11 60 views
0

荫正从后端数据的表,现在我想这些数据如何将数据绑定到使用knockoutjs在C#中的WebForms

IAM正从后端数据绑定到表中的WebForms这样

[WebMethod] 
    [ScriptMethod]  
    private string GetAll() 
    { 
     SqlConnection con = new SqlConnection(@"Data Source=DEVENV1;Initial Catalog=KnockoutData;Integrated Security=True");  
     SqlCommand cmd = new SqlCommand("select * from sampledb", con); 
     con.Open(); 
     SqlDataReader reader = cmd.ExecuteReader();    
    } 

现在通过使用Web表单的jQuery阿贾克斯IAM获取数据,这样的事情...

<script type="text/javascript"> 
     $(document).ready(function() { 
      $('#btnEdit').click(function() { 
       var viewModel; 
       $.ajax({ 
        type: "GET", 
        url: "KnockoutJs.aspx/GetAll", 
        contentType: "application/json", 
        success: function (data) { 
         var result = JSON.parse(data); 
        } 
       }); 
      }); 
<script> 

现在怎么这个数据绑定到下表,用knockoutJs的foreach

<table border="1"> 
<tr> 
<th>Student Name</th> 
<th>Roll No </th> 
</tr>   
</table> 
+0

看看这个淘汰赛[文档](http://knockoutjs.com/documentation/foreach-binding.html) – Martyn0627 2013-02-11 09:50:35

回答

0

在viewModel之前在javascript类中添加构造函数并将此值解析为该构造函数。 检查此链接可能会对您有所帮助: Dynamic table in knockoutjs

相关问题