Solution to add 2 cells to a asp:Table TableRow. I'm pulling the data for the table from a database and removing the comma separated items with the string function.
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);
}
}
}
}
}
Here is the that I have in my 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>