在表格的行和列之间绘制边框

问题描述 投票:2回答:2

如何在asp.net(C#)表的行和列之间绘制边框?

我有以下内容:

<asp:Table ID="Table1" runat="server" BackColor="White" BorderColor="Black" 
        BorderWidth="1px" ForeColor="Black">
    </asp:Table>

在代码隐藏文件中我添加行:

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

但是,我没有看到表格的行和列之间有任何边界。该表是:

那么,如何在asp.net表的行和列之间绘制边框?

asp.net html-table border rows
2个回答
6
投票

您缺少两个属性

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绘制边框:

#table1 {
  border: solid thin black;
}

#table1 td {
  border: solid thin black;
}

此外,通过代码创建表是不好的!您应该考虑使用Repeater控件。

© www.soinside.com 2019 - 2024. All rights reserved.