Share via


HtmlTableRow.Cells プロパティ

HtmlTable コントロールの行に格納されているセルを表す HtmlTableCell オブジェクトのコレクションを取得します。

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

構文

'宣言
Public Overridable ReadOnly Property Cells As HtmlTableCellCollection
'使用
Dim instance As HtmlTableRow
Dim value As HtmlTableCellCollection

value = instance.Cells
public virtual HtmlTableCellCollection Cells { get; }
public:
virtual property HtmlTableCellCollection^ Cells {
    HtmlTableCellCollection^ get ();
}
/** @property */
public HtmlTableCellCollection get_Cells ()
public function get Cells () : HtmlTableCellCollection
適用できません。

プロパティ値

HtmlTable コントロールの行のセルを格納している HtmlTableCellCollection

解説

Cells コレクションを使用して、HtmlTable コントロールの行のセルにプログラムによってアクセスします。コレクションのセルの追加、削除、および挿入をプログラムで行うことができます。

メモメモ :

行にセルが定義されていない場合は、空の HtmlTableCellCollection オブジェクトが返されます。

使用例

Cells コレクションを使用して、HtmlTableRow オブジェクトで表される行のセルを反復処理する方法を次のコード例に示します。その後、セルは新しい内容に更新されます。

<%@ 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
            
        ' Change the inner HTML of the cell.
        Table1.Rows(i).Cells(j).InnerHtml = "Row " & i.ToString() & _
                                            ", Column " & j.ToString()
      Next j

    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>


      <br /><br />
  
      <input type="button" 
             value="Change Table Contents"
             onserverclick="Button_Click" 
             runat="server"/>

   </form>

</body>
</html>
<%@ 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++)
      {
        // Change the inner HTML of the cell.
        Table1.Rows[i].Cells[j].InnerHtml = "Row " + i.ToString() +
                                            ", Column " + j.ToString();
      }

    }

  }

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


      <br /><br />
  
      <input type="button" 
             value="Change Table Contents"
             onserverclick ="Button_Click" 
             runat="server"/>

   </form>

</body>
</html>
<%@ Page Language="JScript" 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">

  function Button_Click(sender, e : EventArgs) 
  {

    // Iterate through the rows of the table.
    for (var i : int=0; i<=Table1.Rows.Count - 1; i++)
    {

      // Iterate through the cells of a row.
      for (var j : int =0; j<=Table1.Rows[i].Cells.Count - 1; j++)
      {
        // Change the inner HTML of the cell.
        Table1.Rows[i].Cells[j].InnerHtml = "Row " + i.ToString() + 
                                                   ", Column " + j.ToString(); 
      }

    }

  }

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


      <br /><br />
  
      <input type="button" 
             value="Change Table Contents"
             onserverclick="Button_Click" 
             runat="server"/>

   </form>

</body>
</html>

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

HtmlTableRow クラス
HtmlTableRow メンバ
System.Web.UI.HtmlControls 名前空間
HtmlTableCellCollection

その他の技術情報

HTML サーバー コントロール