如何从 asp.net 访问纯 html 表的单元格内容

本文关键字:单元格 html asp net 访问 | 更新日期: 2023-09-27 18:36:38

我有一个表格:

<table id="trTable" runat="server" clientidmode="Static">
        <thead>
            <tr>
                <th style="display:none">
                    ID
                </th>
                <th style="width: 112px">
                    Item
                </th>
                <th style="width: 40px; text-align: left">
                    Price
                </th>
                <th style="width: 24px; text-align: center">
                </th>
                <th style="width: 26px; text-align: center">
                    Qty
                </th>
                <th style="width: 24px; text-align: center">
                </th>
                <th style="width: 40px; text-align: right">
                    Total
                </th>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>

并使用jQuery向其添加新行:

var newRow = $("<tr> <td class='drinkID' style='display:none'>" + drinkID + "</td> <td class='drinkName'>" + dName + "</td>  <td class='drinkPrice'>" + dPrice + "</td>  <td style='text-align:center'><input id='Button' type='button' value='<' class='minusButton' /> </td>  <td class='drinkQty'>1</td>  <td style='text-align:center'><input id='Button' type='button' value='>' class='"plusButton'" /></td>  <td class='drinkTotal'>" + dPrice + "</td>  </tr>");

如何使用 asp.net 访问单元格的内容?

我正在使用:

foreach (HtmlTableRow row in trTable.Rows)
        {
            Response.Write("RowDetails:" + row.Cells[1].InnerHtml);
        }

但是响应.write只输出:

RowDetails: Item

为什么它没有得到单元格内容?

如何从 asp.net 访问纯 html 表的单元格内容

您在客户端的html结构页面上更改的内容不会发送回服务器上,并且对此一无所知。

换句话说,页面上的内容并没有完全打磨回服务器上。

要解决此问题,您可以同时进行两次编辑,一次针对用户看到的内容,另一次隐藏在隐藏的输入上,以将更改回发到服务器并在服务器端重新创建表。

希望这能拍到现场。

您还可以

使用 Microsoft Ajax 在行中启用部分渲染。这将执行相同的回发效果,但只会将受影响的内容发送到客户端。