HtmlTableRowCollection.Insert メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HtmlTableRowCollection.Insert メソッドの意味・解説 

HtmlTableRowCollection.Insert メソッド

コレクション内の指定した位置HtmlTableRow オブジェクト追加します

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

Public Sub Insert ( _
    index As Integer, _
    row As HtmlTableRow _
)
Dim instance As HtmlTableRowCollection
Dim index As Integer
Dim row As HtmlTableRow

instance.Insert(index, row)
public void Insert (
    int index,
    HtmlTableRow row
)
public:
void Insert (
    int index, 
    HtmlTableRow^ row
)
public void Insert (
    int index, 
    HtmlTableRow row
)
public function Insert (
    index : int, 
    row : HtmlTableRow
)

パラメータ

index

HtmlTableRow を追加する HtmlTableRowCollection 内の位置

row

HtmlTableRowCollection追加する HtmlTableRow

解説解説
使用例使用例

Insert メソッド使用してHtmlTableRowCollection コレクションHtmlTableRow オブジェクトが表すテーブルの行を挿入する方法次のコード例示します

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

<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 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.Insert(i, cell)
            
      Next i

      Table1.Rows.Insert(j, row)
         
    Next j
      
  End Sub

</script>

<html>
<head>
   <title>HtmlTableRowCollection Example</title>
</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>
<%@ Page Language="C#" AutoEventWireup="True" %>

<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.Insert(i, cell);
      }
      Table1.Rows.Insert(j, row);
    }
  }

</script>

<html>
<head>
   <title>HtmlTableRowCollection Example</title>
</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>
<%@ 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.Insert(i, cell);
            }
            Table1.Rows.Insert(j, 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>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HtmlTableRowCollection クラス
HtmlTableRowCollection メンバ
System.Web.UI.HtmlControls 名前空間
HtmlTableCell クラス
HtmlTableRow クラス
HtmlTableRow.Cells プロパティ



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

辞書ショートカット

すべての辞書の索引

HtmlTableRowCollection.Insert メソッドのお隣キーワード
検索ランキング

   

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



HtmlTableRowCollection.Insert メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS