Draw border between rows and cols of table

35,892

Solution 1

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

Solution 2

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.

Share:
35,892
Nurlan
Author by

Nurlan

java, c++, c#

Updated on December 31, 2020

Comments

  • Nurlan
    Nurlan over 3 years

    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:

    enter image description here

    So, how to draw borders between rows and cols of the asp.net table?

  • Amir Rezvani
    Amir Rezvani almost 12 years
    For css styling you can use: #Table1 { border-collapse:collapse; } #Table1, td, th #Table1 { border:1px solid black; }