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