HtmlTable クラスとは? わかりやすく解説

HtmlTable クラス

サーバー上で HTML <table> 要素に、プログラムアクセスできるようにします。

名前空間: System.Web.UI.HtmlControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Class HtmlTable
    Inherits HtmlContainerControl
public class HtmlTable : HtmlContainerControl
public ref class HtmlTable : public
 HtmlContainerControl
public class HtmlTable extends HtmlContainerControl
public class HtmlTable extends
 HtmlContainerControl
解説解説

HtmlTable コントロール使用してサーバー上の HTML <table> 要素プログラム制御します。これによって Web ページテーブル作成できます

さらに、BgColorBorder、BorderColor、HeightWidth の各プロパティ設定して<table> 要素外観動的に変更できますまた、AlignCellPadding、および CellSpacing の各プロパティ設定すると、セル内容表示方法制御できます

HtmlTable コントロールの行はコントロールRows プロパティ格納されます。これによってテーブル各行プログラムによってアクセスできます

メモメモ

複合テーブル モデルサポートされていません。<caption><col><colgroup><tbody><thead><tfoot>各要素入れ子になっている HtmlTable コントロールを持つことはできません。これらの要素警告なしに削除され出力 HTML には表示されません。これらのテーブル モデル要素HtmlTable コントロールの Control.Controls コレクションプログラム使って追加しようとすると、例外スローさます。

HtmlTableインスタンス初期プロパティ値の一覧については、HtmlTable コンストラクタトピック参照してください

TopicLocation
方法 : ASP.NET 構文使用して HTML サーバー コントロールWeb ページ追加するASP .NET Web アプリケーション作成
方法 : HTML サーバー コントロール プロパティプログラム設定するASP .NET Web アプリケーション作成
方法 : HTML テーブル要素内容選択するVisual Studio での ASP .NET Web アプリケーション作成
方法 : HTML テーブル要素サイズ変更するVisual Studio での ASP .NET Web アプリケーション作成
方法 : Table Web サーバー コントロールに行およびセル動的に追加するASP .NET Web アプリケーション作成
方法 : デザイン ビューHTML テーブル作成または編集するVisual Studio での ASP .NET Web アプリケーション作成
使用例使用例

HtmlTable コントロール使用してテーブル内の情報表示する方法次のコード例示します

<%@ Page Language="VB" AutoEventWireup="True"
 %>

<script runat="server">

  Sub Button_Click(ByVal sender As
 Object, ByVal e As EventArgs)

    ' Set the properties of the HtmlTable with the
    ' user selections.
    Table1.BgColor = BgColorSelect.Value
    Table1.Border = CInt(BorderSelect.Value)
    Table1.BorderColor = BorderColorSelect.Value
    Table1.Height = HeightSelect.Value
    Table1.Width = WidthSelect.Value
    
  End Sub
  
</script>

<html>
<head>
   <title>HtmlTable Example</title>
</head>
<body>

   <form runat="server">

      <h3>HtmlTable Example</h3>

      <table id="Table1" 
             Border="1" 
             BorderColor="black" 
             runat="server">

         <tr>
            <th>
               Column 1
            </th>
            <th>
               Column 2
            </th>
            <th>
               Column 3
            </th>
         </tr>
         <tr>
            <td>
               Cell 1
            </td>
            <td>
               Cell 2
            </td>
            <td>
               Cell 3
            </td>
         </tr>
         <tr>
            <td>
               Cell 4
            </td>
            <td>
               Cell 5
            </td>
            <td>
               Cell 6
            </td>
         </tr>

      </table>
      
      <hr>

      Select the display settings: <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>White</option>
        
      </select>

      &nbsp;&nbsp;

      Border:
      <select id="BorderSelect" 
              runat="server">

         <option Value="0">0</option>
         <option Value="1" Selected>1</option>
         <option Value="2">2</option>
         <option Value="3">3</option>
         <option Value="4">4</option>
         <option Value="5">5</option>

      </select>

      &nbsp;&nbsp;

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

      &nbsp;&nbsp;

      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="C#" AutoEventWireup="True" %>

<script runat="server">

  void Button_Click(Object sender, EventArgs e)
  {

    // Set the properties of the HtmlTable with the
    // user selections.
    Table1.BgColor = BgColorSelect.Value;
    Table1.Border = Convert.ToInt32(BorderSelect.Value);
    Table1.BorderColor = BorderColorSelect.Value;
    Table1.Height = HeightSelect.Value;
    Table1.Width = WidthSelect.Value;

  }

</script>

<html>
<head>
   <title>HtmlTable Example</title>
</head>
<body>

   <form runat="server">

      <h3>HtmlTable Example</h3>

      <table id="Table1" 
             Border="1" 
             BorderColor="black" 
             runat="server">

         <tr>
            <th>
               Column 1
            </th>
            <th>
               Column 2
            </th>
            <th>
               Column 3
            </th>
         </tr>
         <tr>
            <td>
               Cell 1
            </td>
            <td>
               Cell 2
            </td>
            <td>
               Cell 3
            </td>
         </tr>
         <tr>
            <td>
               Cell 4
            </td>
            <td>
               Cell 5
            </td>
            <td>
               Cell 6
            </td>
         </tr>

      </table>
      
      <hr>

      Select the display settings: <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>White</option>
        
      </select>

      &nbsp;&nbsp;

      Border:
      <select id="BorderSelect" 
              runat="server">

         <option Value="0">0</option>
         <option Value="1" Selected>1</option>
         <option Value="2">2</option>
         <option Value="3">3</option>
         <option Value="4">4</option>
         <option Value="5">5</option>

      </select>

      &nbsp;&nbsp;

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

      &nbsp;&nbsp;

      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="JScript" AutoEventWireup="True" %>

<script runat="server">

  function Button_Click(sender : Object, e : EventArgs)
  { 

    // Set the properties of the HtmlTable with the
    // user selections.
    Table1.BgColor = BgColorSelect.Value;
    Table1.Border = Convert.ToInt32(BorderSelect.Value);
    Table1.BorderColor = BorderColorSelect.Value;
    Table1.Height = HeightSelect.Value;
    Table1.Width = WidthSelect.Value;

  }

</script>

<html>
<head>
   <title>HtmlTable Example</title>
</head>
<body>

   <form runat="server">

      <h3>HtmlTable Example</h3>

      <table id="Table1" 
             Border="1" 
             BorderColor="black" 
             runat="server">

         <tr>
            <th>
               Column 1
            </th>
            <th>
               Column 2
            </th>
            <th>
               Column 3
            </th>
         </tr>
         <tr>
            <td>
               Cell 1
            </td>
            <td>
               Cell 2
            </td>
            <td>
               Cell 3
            </td>
         </tr>
         <tr>
            <td>
               Cell 4
            </td>
            <td>
               Cell 5
            </td>
            <td>
               Cell 6
            </td>
         </tr>

      </table>
      
      <hr>

      Select the display settings: <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>White</option>
        
      </select>

      &nbsp;&nbsp;

      Border:
      <select id="BorderSelect" 
              runat="server">

         <option Value="0">0</option>
         <option Value="1" Selected>1</option>
         <option Value="2">2</option>
         <option Value="3">3</option>
         <option Value="4">4</option>
         <option Value="5">5</option>

      </select>

      &nbsp;&nbsp;

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

      &nbsp;&nbsp;

      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>

HtmlTable コントロール動的に作成する方法次のコード例示します

<%@ Page Language="VB" %>

<script runat="server">

  Sub Page_Load(ByVal sender As
 Object, ByVal e As EventArgs)

    Dim i As Integer
    Dim j As Integer
    Dim row As HtmlTableRow
    Dim cell As HtmlTableCell

    ' Get the number of rows and columns selected by the user.
    Dim numrows As Integer
 = CInt(Select1.Value)
    Dim numcells As Integer
 = CInt(Select2.Value)

    ' Iterate through the rows.
    For j = 0 To numrows - 1

      ' Create a new row.
      row = New HtmlTableRow()

      ' Provide a different background color for alternating rows.
      If (j Mod 2) = 1 Then
        row.BgColor = "Gray"
      End If

      ' Iterate through the cells of a row.
      For i = 0 To numcells - 1
        
        ' Create a new cell and add it to the HtmlTableRow
        ' Cells collection.
        cell = New HtmlTableCell()
        cell.Controls.Add(New LiteralControl("row
 " & _
                                          j.ToString() & _
                                          ", cell "
 & _
                                          i.ToString()))
        row.Cells.Add(cell)
            
      Next i

      ' Add the row to the HtmlTable Rows collection.
      Table1.Rows.Add(row)
         
    Next j
      
  End Sub

</script>

<html>
<head>
   <title>HtmlTable Example</title>
</head>
<body>

   <form runat="server">

      <h3>HtmlTable Example</h3>

      <table id="Table1" 
             CellPadding="5" 
             CellSpacing="0" 
             Border="1" 
             BorderColor="black" 
             runat="server"/>
        
      <hr>

      Select the number of rows and
 columns to create: <br><br>

      Table rows:
      <select id="Select1" 
              runat="server">

         <option Value="1">1</option>
         <option Value="2">2</option>
         <option Value="3">3</option>
         <option Value="4">4</option>
         <option Value="5">5</option>

      </select>

      &nbsp;&nbsp;

      Table cells:
      <select id="Select2" 
              runat="server">

         <option Value="1">1</option>
         <option Value="2">2</option>
         <option Value="3">3</option>
         <option Value="4">4</option>
         <option Value="5">5</option>

      </select>
       
      <br><br>
  
      <input type="submit" 
             value="Generate Table" 
             runat="server"/>

   </form>

</body>
</html>
<%@ Page Language="C#" %>

<script runat="server">

  void Page_Load(Object sender, EventArgs e)
  {

    // Get the number of rows and columns selected by the user.
    int numrows = Convert.ToInt32(Select1.Value);
    int numcells = Convert.ToInt32(Select2.Value);

    // Iterate through the rows.
    for (int j = 0; j < numrows; j++)
    {

      // Create a new row and add it to the Rows collection.
      HtmlTableRow row = new HtmlTableRow();

      // Provide a different background color for alternating rows.
      if (j % 2 == 1)
        row.BgColor = "Gray";

      // Iterate through the cells of a row.
      for (int i = 0; i < numcells; i++)
      {
        // Create a new cell and add it to the HtmlTableRow 
        // Cells collection.
        HtmlTableCell cell = new HtmlTableCell();
        cell.Controls.Add(new LiteralControl("row "
 +
                          j.ToString() +
                          ", cell " +
                          i.ToString()));
        row.Cells.Add(cell);
      }

      // Add the row to the HtmlTable Rows collection.
      Table1.Rows.Add(row);
    }
  }

</script>

<html>
<head>
   <title>HtmlTable Example</title>
</head>
<body>

   <form runat="server">

      <h3>HtmlTable Example</h3>

      <table id="Table1" 
             CellPadding="5" 
             CellSpacing="0" 
             Border="1" 
             BorderColor="black" 
             runat="server"/>
        
      <hr>

      Select the number of rows and columns to create: <br><br>

      Table rows:
      <select id="Select1" 
              runat="server">

         <option Value="1">1</option>
         <option Value="2">2</option>
         <option Value="3">3</option>
         <option Value="4">4</option>
         <option Value="5">5</option>

      </select>

      &nbsp;&nbsp;

      Table cells:
      <select id="Select2" 
              runat="server">

         <option Value="1">1</option>
         <option Value="2">2</option>
         <option Value="3">3</option>
         <option Value="4">4</option>
         <option Value="5">5</option>

      </select>
       
      <br><br>
  
      <input type="submit" 
             value="Generate Table" 
             runat="server"/>

   </form>

</body>
</html>
<%@ Page Language="JScript" %>

<script runat="server">

  function Page_Load(sender : Object, e : EventArgs) 
  {

    // Get the number of rows and columns selected by the user.
    var numrows : int = Convert.ToInt32(Select1.Value);
    var numcells : int = Convert.ToInt32(Select2.Value);

    // Iterate through the rows.
    for (var j : int = 0;
 j < numrows; j++) 
    {

      // Create a new row and add it to the Rows collection.
      var row : HtmlTableRow = new HtmlTableRow();

      // Provide a different background color for alternating rows.
      if (j%2 == 1)
        row.BgColor="Gray";

      // Iterate through the cells of a row.
      for (var i : int =
 0; i < numcells; i++) 
      {
        // Create a new cell and add it to the HtmlTableRow 
        // Cells collection.
        var cell : HtmlTableCell = new HtmlTableCell();
        cell.Controls.Add(new LiteralControl("row "
 + 
                      j.ToString() + 
                      ", cell " +
                     i.ToString()));
        row.Cells.Add(cell);
      }
      
      // Add the row to the HtmlTable Rows collection.
      Table1.Rows.Add(row);
    }
  }

</script>

<html>
<head>
   <title>HtmlTable Example</title>
</head>
<body>

   <form runat="server">

      <h3>HtmlTable Example</h3>

      <table id="Table1" 
             CellPadding="5" 
             CellSpacing="0" 
             Border="1" 
             BorderColor="black" 
             runat="server"/>
        
      <hr>

      Select the number of rows and columns to create: <br><br>

      Table rows:
      <select id="Select1" 
              runat="server">

         <option Value="1">1</option>
         <option Value="2">2</option>
         <option Value="3">3</option>
         <option Value="4">4</option>
         <option Value="5">5</option>

      </select>

      &nbsp;&nbsp;

      Table cells:
      <select id="Select2" 
              runat="server">

         <option Value="1">1</option>
         <option Value="2">2</option>
         <option Value="3">3</option>
         <option Value="4">4</option>
         <option Value="5">5</option>

      </select>
       
      <br><br>
  
      <input type="submit" 
             value="Generate Table" 
             runat="server"/>

   </form>

</body>
</html>
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.Control
     System.Web.UI.HtmlControls.HtmlControl
       System.Web.UI.HtmlControls.HtmlContainerControl
        System.Web.UI.HtmlControls.HtmlTable
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HtmlTable メンバ
System.Web.UI.HtmlControls 名前空間
HtmlContainerControl クラス
HtmlTableCell
HtmlTableCellCollection
HtmlTableRow
HtmlTableRowCollection
その他の技術情報
HTML サーバー コントロール



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「HtmlTable クラス」の関連用語

HtmlTable クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HtmlTable クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS