Share via


HtmlTableRow.BgColor プロパティ

定義

HtmlTableRow クラスのインスタンスで表される行の背景色を取得または設定します。

public:
 property System::String ^ BgColor { System::String ^ get(); void set(System::String ^ value); };
public string BgColor { get; set; }
member this.BgColor : string with get, set
Public Property BgColor As String

プロパティ値

HtmlTableRow のインスタンスで表される行の背景色。

次のコード例では、 プロパティを使用 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++)
    {

      // Update the properties of each row. 
      Table1.Rows[i].BgColor = BgColorSelect.Value;
      Table1.Rows[i].BorderColor = BorderColorSelect.Value;
      Table1.Rows[i].Height = HeightSelect.Value;

    }

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>HtmlTableRow Example</title>
</head>
<body>

   <form id="form1" runat="server">

      <h3>HtmlTableRow Example</h3>

      <table id="Table1" 
             style="border-width:1; border-color:Black"
             runat="server">

         <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 rows 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>
       
      <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

    ' Iterate through the rows of the table.
    For i = 0 To Table1.Rows.Count - 1

      ' Update the properties of each row. 
      Table1.Rows(i).BgColor = BgColorSelect.Value
      Table1.Rows(i).BorderColor = BorderColorSelect.Value
      Table1.Rows(i).Height = HeightSelect.Value

    Next i

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>HtmlTableRow Example</title>
</head>
<body>

   <form id="form1" runat="server">

      <h3>HtmlTableRow Example</h3>

      <table id="Table1" 
             style="border-width:1; border-color:Black"
             runat="server">

         <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 rows 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>
       
      <br /><br />
  
      <input id="Button1" type="button" 
             value="Generate Table"
             onserverclick="Button_Click" 
             runat="server"/>

   </form>

</body>
</html>

注釈

クラスの BgColor インスタンスによって表される行の背景色を指定するには、 プロパティを HtmlTableRow 使用します。 色は、名前で指定することも、16 進値の前にシャープ記号 (#) を付けることで、#RRGGBB形式で指定することもできます。 RR、GG、BB は、それぞれ色の赤、緑、青の成分を示す 0 ~ 255 の 16 進数の値を表します。 たとえば、#0000FF値は青の色を表します。 赤と緑のコンポーネントの最小値 (00) を指定し、青のコンポーネントの最大値 (FF) を指定します。

次の表は、16 個の定義済みの HTML 色名と、 プロパティに使用できる対応する 16 進値を BgColor 示しています。 HTML の色の詳細については、 World Wide Web Consortium (W3C) Web サイトを参照してください。

色名 16 進数値
Aqua #00FFFF
Black #000000
#0000FF
フクシア #FF00FF
グレー #808080
[緑] #008000
ライム #00FF00
茶色 #800000
Navy #000080
オリーブ #808000
パープル #800080
[赤] #FF0000
シルバー #C0C0C0
青緑 #008080
#FFFFFF
#FFFF00

プロパティで BgColor 使用できる色は、 列挙体から KnownColor 決定できます。

色名では大文字と小文字が区別されません。

適用対象

こちらもご覧ください