HtmlTableRow Class

Represents the <tr> HTML element in an HtmlTable control.

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

public class HtmlTableRow : HtmlContainerControl
public class HtmlTableRow extends HtmlContainerControl
public class HtmlTableRow extends HtmlContainerControl

The <tr> element represents a row in a table. Use the HtmlTableRow class to programmatically control the <tr> HTML elements in an HtmlTable control.

The HtmlTableRow class allows you to customize the appearance of a row in a table by specifying the background color, the border color, and the height of the cells in the row. These attributes are set using the BgColor, BorderColor, and Height properties.

You can control the alignment of the contents in the cells for the entire row by using the Align and VAlign properties. The Align property controls the horizontal alignment of the contents of the cells, while the VAlign property controls the vertical alignment.

By using the Cells collection of this class, you can programmatically access the individual cells in a row of a table. This allows you to control the properties of each cell, as well as the content.

For a list of initial property values for an instance of HtmlTableRow, see the HtmlTableRow constructor.

The following code example demonstrates how to use an HtmlTableRow instance to represent a row in the HtmlTable control. An HtmlTableRow is retrieved from the Rows collection of the table and its contents are modified.

<%@ 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();




   <title>HtmlTableRow Example</title>

   <form runat="server">

      <h3>HtmlTableRow Example</h3>

      <table id="Table1" 

               Cell 1
               Cell 2
               Cell 3
               Cell 4


      <input type="button" 
             value="Change Table Contents"
             onserverclick ="Button_Click" 



  • AspNetHostingPermission  for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
  • AspNetHostingPermission  for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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