【问题标题】:How to bind a datable from ASP.Net to handsontable?如何将 ASP.Net 中的数据表绑定到 handsontable?
【发布时间】: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

【问题讨论】:

    标签: jquery asp.net


    【解决方案1】:

    您可以通过数据表循环并使用此表生成数据对象。然后你可以在你的脚本中渲染它。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-22
    • 1970-01-01
    • 2010-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多