我是Handsontable的新手,并希望将asp.net数据绑定到Handsontable。 任何人都可以帮我提供代码片段。我刚刚在我的页面中加载了Handsontable
以下是我的代码:我收到错误 Microsoft JScript运行时错误:'示例'未定义
<body>
<form id="form1" runat="server">
<div id="example"></div>
</form>
</body>
<script type="text/javascript">
function example(dt) {
var data = dt;
$('#example').handsontable({
data: data,
minSpareRows: 1,
colHeaders: false,
contextMenu: true
});
}
</script>
服务器端代码
dt = Load a table here
Dim data As String = GetJson(dt)
Page.ClientScript.RegisterStartupScript(Me.[GetType](), "example", (Convert.ToString("example(") & data) + ");", True)
Public Function GetJson(dt As DataTable) As String
Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer()
Dim rows As New List(Of Dictionary(Of String, Object))()
Dim row As Dictionary(Of String, Object) = Nothing
For Each dr As DataRow In dt.Rows
row = New Dictionary(Of String, Object)()
For Each col As DataColumn In dt.Columns
row.Add(col.ColumnName.Trim(), dr(col))
Next
rows.Add(row)
Next
Return serializer.Serialize(rows)
End Function
答案 0 :(得分:0)
您可以使用数据表进行循环,并使用此表生成数据对象。然后你可以在你的脚本中渲染它。