Reputation: 2960
How to draw a border between rows and cols of the asp.net(C#) table?
I have following:
<asp:Table ID="Table1" runat="server" BackColor="White" BorderColor="Black"
BorderWidth="1px" ForeColor="Black">
</asp:Table>
in the codebehind file I add rows:
for (int i = 0; i < games.Count(); i++)
{
TableRow tr = new TableRow();
for (int j = 0; j < 9; j++)
{
TableCell tc = new TableCell();
tc.Text = games[i].getData(j);
tr.Cells.Add(tc);
}
tr.BorderWidth = 1;
tr.BorderColor = Color.Black;
Table1.Rows.Add(tr);
}
However, I I don't see any border between rows and cols of the table. The table is:
So, how to draw borders between rows and cols of the asp.net table?
Upvotes: 2
Views: 36889
Reputation: 26386
You are missing two attributes
GridLines="Both" BorderStyle="Solid"
Should be
<asp:Table ID="Table1" runat="server" BackColor="White" BorderColor="Black"
BorderWidth="1" ForeColor="Black" GridLines="Both" BorderStyle="Solid">
CSS styling is better though
Upvotes: 6
Reputation: 1526
I would just use CSS to draw the borders:
#table1 {
border: solid thin black;
}
#table1 td {
border: solid thin black;
}
Also, creating a table via code is BAD! You should look into using the Repeater control.
Upvotes: 3