我有一张 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/