0

我正在从后端获取数据,现在我想将该数据绑定到 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();            
    }

现在在 Webforms 中使用 jquery Ajax 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>
4

1 回答 1

0

在 viewModel 之前的 javascript 类中添加一个构造函数,并将该值解析为该构造函数。检查此链接可能会对您有所帮助: Knockoutjs 中的动态表

于 2013-02-11T09:42:46.897 回答