0

我有 jquery table Table: Column Toggle除了我通过删除删除了列选择data-mode="columntoggle"

我已经datatable填充了,并且在表单上有一个按钮。

我想要做的是在datatable保留布局的 jquery 表中填充数据。我知道的唯一方法是Response.Write(table_header)then 循环到Response.Write(table_rows)then Response.write(table_footer)

但它似乎Response.Write()在 asp.net/jquery 中不起作用。

怎么做?

4

1 回答 1

0

这是我解决它的方法

在 aspx 方面

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>

<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.SqlClient" %>


<!DOCTYPE html>
<script runat ="server">
 Function return_result() As DataTable
  ...
  ...
 Return dt
 End Function

</script>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>jQuery Mobile Demos</title>
    <link rel="stylesheet" href="css/themes/default/jquery.mobile-1.3.1.min.css">
    <link rel="stylesheet" href="_assets/css/jqm-demos.css">
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,700">
    <script src="js/jquery.js"></script>
    <script src="_assets/js/index.js"></script>
    <script src="js/jquery.mobile-1.3.1.min.js"></script>
    <style type="text/css">
        .auto-style1
        {
            width: 61px;
        }
        .auto-style2
        {
            width: 540px;
        }
        .style1
        {
        }
        </style>
</head>
<body>
    <form id="form1" runat="server">
    <table style="width: 92%;">
        <tr>
            <td class="auto-style1">
                Num:
            </td>
            <td class="auto-style2">
                <asp:TextBox ID="txt_num" runat="server" type="search"></asp:TextBox>
                <td class="style1">
                    <asp:Button ID="btn_search" runat="server" Text="Search" data-inline="true"
                        data-theme="b" data-icon="search" data-iconpos="left" />
        </tr>
        <tr>
            <td class="auto-style1">
                Name:
            </td>
            <td class="auto-style2">
                <asp:TextBox ID="txt_name" runat="server" type="text"></asp:TextBox>
            </td>
            <td>
                <asp:Button ID="btn_balance" runat="server" Text="Get Balance" data-inline="true"
                    data-theme="b" data-icon="grid" data-iconpos="left" />
        </tr>
        <tr>
            <td class="auto-style1">
                &nbsp;
            </td>
            <td class="auto-style2">
                &nbsp;
            </td>
            <td>
                &nbsp;</tr>
    </table>

    </form>

    <div>

    </div>
    <!-- table start here -->
    <div>
    <% If IsPostBack and btn_balance.ToolTip = "click"  Then
            Dim tb1_header = "<table data-role=""table"" id=""table-custom-2"" data-mode="""" class=""ui-body-d ui-shadow table-stripe ui-responsive""><thead><tr class=""ui-bar-d""><th data-priority=""2"">Date</th><th>Desc</th><th data-priority=""3"">Credit</th><th data-priority=""1""><abbr title=""Rotten Tomato Rating"">Debit</abbr></th><th data-priority=""5"" class=""style2"">Balance</th></tr></thead>"
            Response.Write(tb1_header)
            Dim dt = return_result()
            Response.Write("<tbody>")
            For i = 0 to dt.Rows.Count - 1
                Dim tbl_row = "<th>" & dt(i)(0) & "</th><td>" & dt(i)(1) & "</td><td>" & dt(i)(2) & "</td><td>" & dt(i)(3) & "</td><td>" & dt(i)(4) & "</td></tr>"    
                Response.Write(tbl_row)
            Next


            Response.Write("</tbody></table>")

       End If
        %>
    </div>
</html>

在 aspx.vb 端

Imports System.Data.SqlClient
Imports System.Data
Imports System.Web.Script.Serialization

Partial Class Default2
    Inherits System.Web.UI.Page
    Dim CONN As New SqlConnection

    Function ConnectToSqlServer(ByVal Server As String, ByVal Database As String, ByVal Username As String, ByVal Password As String) 
        ...
        ...
        Return sql_conn
    End Function

    Protected Sub btn_search_Click(sender As Object, e As System.EventArgs) Handles btn_search.Click
        btn_balance.ToolTip = "notclick"
        ... get_the_customer_name and display it in txt_name
    End Sub

    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        CONN = ConnectToSqlServer(my_server, my_data, my_uid, my_pwd)
    End Sub

    Protected Sub btn_balance_Click(sender As Object, e As System.EventArgs) Handles btn_balance.Click
        btn_balance.ToolTip = "click"
    End Sub
End Class
于 2013-05-22T14:40:01.743 回答