【发布时间】:2014-12-31 01:27:24
【问题描述】:
在 ASP.NET 中,我正在动态创建一个表,包括列和行。
<table>
<thead>
<tr>
<th scope="col">To location</th>
@foreach (String itemName in ViewBag.itemNames)
{
<th scope="col">@itemName</th>
}
</tr>
</thead>
<tbody>
@foreach (var transaction in Model)
{
<tr>
<td>@transaction.toLocation</td>
@foreach (var item in transaction.itemList)
{
<td>@item.quantity</td>
}
</tr>
}
</tbody>
</table>
在 thead 元素中,我得到一列,其中包含项目发送到的位置,以及可能在事务中的每个项目的列。 tbody 元素中使用的 itemList 与 thead 中的 itemName 列的名称相同,加上项目的数量。我正在寻找的第二个 foreach 循环是这样的:
foreach(item in transaction.itemList)
{
@thead.findColumn(@item.itemName) // find the column name that's the same as the itemName
<td>@item.quantity</td> // place the data in that column
}
有人知道怎么做吗?
【问题讨论】: