2012-09-21 20 views
2

如何在asp.net(C#)表的行和列之間繪製邊框?在表的行和列之間繪製邊框

我有以下幾點:

​​

在代碼隱藏文件中我添加行:

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); 
      } 

不過,我看不到行和表之間的cols任何邊界。 表是:

enter image description here

那麼,如何在asp.net錶行和cols之間繪製邊框?

回答

2

我只想用CSS來繪製邊框:

#table1 { 
    border: solid thin black; 
} 

#table1 td { 
    border: solid thin black; 
} 

此外,通過代碼創建一個表是壞的!你應該看看使用Repeater控制。

4

你缺少兩個屬性

GridLines="Both" BorderStyle="Solid" 

應該

<asp:Table ID="Table1" runat="server" BackColor="White" BorderColor="Black" 
    BorderWidth="1" ForeColor="Black" GridLines="Both" BorderStyle="Solid"> 

CSS樣式比較好,雖然

+2

CSS樣式,你可以用:#表1 { 邊界崩潰:崩潰; } #Table1,td,th#Table1 { border:1px solid black; } – CjCoax