HtmlTableCell.BgColor 属性    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置由 HtmlTableCell 类的实例所表示的单元格的背景色。
public:
 property System::String ^ BgColor { System::String ^ get(); void set(System::String ^ value); };public string BgColor { get; set; }member this.BgColor : string with get, setPublic Property BgColor As String属性值
HtmlTableCell 的实例所表示的单元格的背景色。
示例
下面的代码示例演示如何使用 BgColor 属性以编程方式控制控件中 HtmlTable 单元格的背景色。
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  void Button_Click(Object sender, EventArgs e)
  {
    // Iterate through the rows of the table.
    for (int i = 0; i <= Table1.Rows.Count - 1; i++)
    {
      // Iterate through the cells of a row.
      for (int j = 0; j <= Table1.Rows[i].Cells.Count - 1; j++)
      {
        // Update the properties of each cell. 
        Table1.Rows[i].Cells[j].BgColor = BgColorSelect.Value;
        Table1.Rows[i].Cells[j].BorderColor = BorderColorSelect.Value;
        Table1.Rows[i].Cells[j].Height = HeightSelect.Value;
        Table1.Rows[i].Cells[j].Width = WidthSelect.Value;
      }
    }
  }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>HtmlTableCell Example</title>
</head>
<body>
   <form id="form1" runat="server">
      <h3>HtmlTableCell Example</h3>
          <table id="Table1" runat="server" 
                style="border-width: 1; border-color: Black">
         <tr>
            <td>
               Cell 1.
            </td>
            <td>
               Cell 2.
            </td>
         </tr>
         <tr>
            <td>
               Cell 3.
            </td>
            <td>
               Cell 4.
            </td>
         </tr>
      </table>
      <hr />
      Select the display settings for the cells in the table: <br /><br />
      BgColor:
      <select id="BgColorSelect" 
              runat="server">
         <option value="Red">Red</option>
         <option value="Blue">Blue</option>
         <option value="Green">Green</option>
         <option value="Black">Black</option>
         <option value="White" selected="selected">White</option>
        
      </select>
        
      BorderColor:
      <select id="BorderColorSelect" 
              runat="server">
         <option value="Red">Red</option>
         <option value="Blue">Blue</option>
         <option value="Green">Green</option>
         <option value="Black" selected="selected">Black</option>
         <option value="White">White</option>
      </select>
      <br /><br />
      Height:
      <select id="HeightSelect" 
              runat="server">
         <option value="0">0</option>
         <option value="100">100</option>
         <option value="150">150</option>
         <option value="200">200</option>
         <option value="250">250</option>
      </select>
        
      Width:
      <select id="WidthSelect" 
              runat="server">
         <option value="0">0</option>
         <option value="200">200</option>
         <option value="250">250</option>
         <option value="300">300</option>
         <option value="350">350</option>
      </select>
       
      <br /><br />
  
      <input type="button" 
             value="Generate Table"
             onserverclick="Button_Click" 
             runat="server"/>
   </form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim i As Integer
    Dim j As Integer
    ' Iterate through the rows of the table.
    For i = 0 To Table1.Rows.Count - 1
      ' Iterate through the cells of a row.
      For j = 0 To Table1.Rows(i).Cells.Count - 1
        ' Update the properties of each cell. 
        Table1.Rows(i).Cells(j).BgColor = BgColorSelect.Value
        Table1.Rows(i).Cells(j).BorderColor = BorderColorSelect.Value
        Table1.Rows(i).Cells(j).Height = HeightSelect.Value
        Table1.Rows(i).Cells(j).Width = WidthSelect.Value
            
      Next j
    Next i
  End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>HtmlTableCell Example</title>
</head>
<body>
   <form id="form1" runat="server">
      <h3>HtmlTableCell Example</h3>
          <table id="Table1" runat="server" 
                style="border-width: 1; border-color: Black">
         <tr>
            <td>
               Cell 1.
            </td>
            <td>
               Cell 2.
            </td>
         </tr>
         <tr>
            <td>
               Cell 3.
            </td>
            <td>
               Cell 4.
            </td>
         </tr>
      </table>
      <hr />
      Select the display settings for the cells in the table: <br /><br />
      BgColor:
      <select id="BgColorSelect" 
              runat="server">
         <option value="Red">Red</option>
         <option value="Blue">Blue</option>
         <option value="Green">Green</option>
         <option value="Black">Black</option>
         <option value="White" selected="selected">White</option>
        
      </select>
        
      BorderColor:
      <select id="BorderColorSelect" 
              runat="server">
         <option value="Red">Red</option>
         <option value="Blue">Blue</option>
         <option value="Green">Green</option>
         <option value="Black" selected="selected">Black</option>
         <option value="White">White</option>
      </select>
      <br /><br />
      Height:
      <select id="HeightSelect" 
              runat="server">
         <option value="0">0</option>
         <option value="100">100</option>
         <option value="150">150</option>
         <option value="200">200</option>
         <option value="250">250</option>
      </select>
        
      Width:
      <select id="WidthSelect" 
              runat="server">
         <option value="0">0</option>
         <option value="200">200</option>
         <option value="250">250</option>
         <option value="300">300</option>
         <option value="350">350</option>
      </select>
       
      <br /><br />
  
      <input type="button" 
             value="Generate Table"
             onserverclick="Button_Click" 
             runat="server"/>
   </form>
</body>
</html>
注解
BgColor使用 属性可以指定由 类的实例表示的HtmlTableCell单元格的背景色。 可以按名称或使用十六进制值指定颜色,前面有井号字符 (#) ,格式为 #RRGGBB。 RR、GG 和 BB 分别表示 0 到 255 之间的十六进制值,分别指示颜色的红色、绿色和蓝色分量。 例如,#0000FF的值表示蓝色。 它指定红色和绿色组件的最小值 (00) ,同时指定蓝色分量 (FF) 的最大值。
下表显示了可用于 BgColor 属性的 16 个预定义 HTML 颜色名称和相应的十六进制值。 有关 HTML 颜色的详细信息,请参阅 万维网联合会 (W3C) 网站。
| 颜色名称 | 十六进制值 | 
|---|---|
| Aqua | #00FFFF | 
| 黑色 | #000000 | 
| 蓝色 | #0000FF | 
| 紫 红色 | #FF00FF | 
| 灰色 | #808080 | 
| 绿色 | #008000 | 
| 石灰 | #00FF00 | 
| 褐紫红色 | #800000 | 
| Navy | #000080 | 
| 橄榄 | #808000 | 
| 紫色 | #800080 | 
| Red | #FF0000 | 
| Silver | #C0C0C0 | 
| 青色 | #008080 | 
| White | #FFFFFF | 
| Yellow | #FFFF00 | 
与 属性一起使用的 BgColor 可用颜色可以从 枚举中确定 KnownColor 。
颜色名称不区分大小写。