次の方法で共有


HtmlTableRowCollection クラス

HtmlTable コントロールの行を表す HtmlTableRow オブジェクトのコレクション。このクラスは継承できません。

この型のすべてのメンバの一覧については、HtmlTableRowCollection メンバ を参照してください。

System.Object
   System.Web.UI.HtmlControls.HtmlTableRowCollection

NotInheritable Public Class HtmlTableRowCollection
   Implements ICollection, IEnumerable
[C#]
public sealed class HtmlTableRowCollection : ICollection,
   IEnumerable
[C++]
public __gc __sealed class HtmlTableRowCollection : public
   ICollection, IEnumerable
[JScript]
public class HtmlTableRowCollection implements ICollection,
   IEnumerable

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

HtmlTableRowCollection クラスを使用して、 HtmlTable コントロール内の行を表す HtmlTableRow オブジェクトのコレクションをプログラムで管理します。通常、このクラスは、 HtmlTable コントロールの行の内容の追加、削除、または変更に使用します。

メモ    HtmlTable コントロールには、 HtmlTableRow オブジェクトのコレクションを表す Rows プロパティが含まれます。各 HtmlTableRow は、テーブル内の各行を表します。 HtmlTableRow には、 HtmlTableCell オブジェクトのコレクションを表す Cells プロパティが含まれます。これらのオブジェクトは、テーブル内の各セルを順番に表します。各セルを取得するには、最初に HtmlTable コントロールの Rows コレクションから、セルを格納している行を表す HtmlTableRow を取得します。その後、 HtmlTableRowCells コレクションから、行のセルを表す HtmlTableCell を取得できます。

使用例

[Visual Basic, C#, JScript] HtmlTableRowCollection に行を追加して HtmlTable コントロールの内容を動的に生成する方法の例を次に示します。テーブルの Rows プロパティが HtmlTableRowCollection であることに注意してください。

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

<html>
<head>

   <script runat="server">

      Sub Page_Load(sender As Object, 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 and add it to the Rows collection.
            row = New HtmlTableRow()

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

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

            Table1.Rows.Add(row)
         
         Next j
      
      End Sub

   </script>

</head>
<body>

   <form runat="server">

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

[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>

<html>
<head>

   <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="Gainsboro";

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

   </script>

</head>
<body>

   <form runat="server">

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

[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>
<head>

   <script runat="server">

      function Page_Load(sender, 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="Gainsboro";

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

   </script>

</head>
<body>

   <form runat="server">

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

[C++] C++ のサンプルはありません。Visual Basic、C#、および JScript のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Web.UI.HtmlControls

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Web (System.Web.dll 内)

参照

HtmlTableRowCollection メンバ | System.Web.UI.HtmlControls 名前空間 | HtmlTable | Rows | HtmlTableRow | Cells | HtmlTableCell