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

标签 c# jquery asp.net

我有一张 table :

<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);
        }

但是 response.write 只是输出:

RowDetails: Item

为什么没有获取单元格内容?

最佳答案

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

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

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

希望这能引起轰动。

关于c# - 如何从 asp.net 访问纯 html 表格的单元格内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10968008/

相关文章:

javascript - Bootstrap 日期时间选择器删除子午线上午/下午

javascript - 使用 ajax 的 jQuery 调用没有响应,没有错误

javascript - 将注册表单中提交的姓名发布到感谢页面

c# - 如何在代码隐藏中使用 wpflocalizeextension?

c# - 在 C# 中使用 PowerShell 导入 CSV 添加列

Javascript 循环无法正确创建 jquery 控件

javascript - Controller 名称随机添加到 URL 中

asp.net - 如何将使用 Ajax webmethods 的 ASP.NET 页面转换为支持 Ajax 的服务器控件?

c# - 使用持续集成修改 .NET 项目文件

c# - 在 Windows 应用商店应用程序中使用 httpclient 获取 UTF-8 响应