将 2 个单元格添加到 asp:Table TableRow 的解决方案。我正在从数据库中提取表的数据并使用字符串函数删除逗号分隔的项目。
protected void listView_Bids(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
TextBox TextBoxHighlights = (TextBox)e.Item.FindControl("TextBox2");
Table FindHighlightTable = (Table)e.Item.FindControl("bidHighlightTable");
if (TextBoxHighlights != null)
{
string benefits = (TextBoxHighlights.Text.ToString());
TableRow row = new TableRow();
int i = 0;
string[] words = benefits.Split(',');
foreach (string word in words)
{
if (i == 0 || i % 2 == 0)
{
row = new TableRow();
}
TableCell cell1 = new TableCell();
cell1.Text = word.ToString();
row.Cells.Add(cell1);
i++;
if (i % 2 == 0)
{
FindHighlightTable.Rows.Add(row);
}
}
}
}
}
这是我在 ListView 中的内容:
<asp:Table ID="bidHighlightTable" CssClass="table table-striped table-bordered bid-highlight-table" runat="server">
<asp:TableRow runat="server">
<asp:TableCell runat="server"></asp:TableCell>
<asp:TableCell runat="server"></asp:TableCell>
</asp:TableRow>
</asp:Table>