This documentation is archived and is not being maintained.

HtmlTableRow Class

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

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

[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class HtmlTableRow : HtmlContainerControl
<asp:HtmlTableRow />

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" %>

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

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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Show: