【发布时间】:2014-12-07 21:12:29
【问题描述】:
我对 Handsontable 非常陌生,希望将 asp.net 数据表绑定到 Handsontable。 谁能帮我写代码sn-p。我刚刚在我的页面中加载了 Handsontable
这是我的代码:我收到一个错误 Microsoft JScript 运行时错误:'example' is undefined
<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
【问题讨论】: