Export (0) Print
Expand All

HtmlTableRow.Cells Property

Gets a collection of HtmlTableCell objects that represent the cells contained in a row of the HtmlTable control.

Namespace: System.Web.UI.HtmlControls
Assembly: System.Web (in system.web.dll)

public virtual HtmlTableCellCollection Cells { get; }
/** @property */
public HtmlTableCellCollection get_Cells ()

public function get Cells () : HtmlTableCellCollection

Property Value

An HtmlTableCellCollection that contains the cells of a row in an HtmlTable control.

Use the Cells collection to programmatically access the cells of a row in an HtmlTable control. You can programmatically add, remove, and insert cells in the collection.

NoteNote

If there are no cells defined in a row, an empty HtmlTableCellCollection object is returned.

The following code example demonstrates how to use the Cells collection to iterate through the cells of a row, represented by an HtmlTableRow object. The cells are then updated with new content.

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

<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>
<head>
   <title>HtmlTableRow Example</title>
</head>
<body>

   <form runat="server">

      <h3>HtmlTableRow Example</h3>

      <table id="Table1" 
             border="1" 
             bordercolor="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 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft