TableRow Class

Represents a row in a Table control.

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

public class TableRow : WebControl
/** @attribute BindableAttribute(false) */ 
public class TableRow extends WebControl
public class TableRow extends WebControl

The TableRow class represents a row in a Table control.

This class allows you to control how the contents of the row are displayed. The alignment of the contents in the row are specified by setting the HorizontalAlign and VerticalAlign properties.

You can programmatically manage the cells in the row by using the Cells collection. The Cells collection is a collection of TableCell objects that represent the cells in the row.

Caution noteCaution

The TableCell control can be used to display user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. ASP.NET provides an input request validation feature to block script and HTML in user input. Validation server controls are also provided to assess user input. For more information, see Validation ASP.NET Controls.

This following code example creates a table, programmatically adds elements to the table, and displays the table on the Web page.

<%@ Page language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>

        <script runat="server">
            private void Page_Load(object sender, System.EventArgs e)
                // Create a TableItemStyle object that can be
                // set as the default style for all cells
                // in the table.
                TableItemStyle tableStyle = new TableItemStyle();
                tableStyle.HorizontalAlign = HorizontalAlign.Center;
                tableStyle.VerticalAlign = VerticalAlign.Middle;
                tableStyle.Width = Unit.Pixel(100);

                // Create more rows for the table.
                for (int i = 2; i < 10; i++)
                    TableRow tempRow = new TableRow();
                    for (int j = 0; j < 3; j++)
                        TableCell tempCell = new TableCell();
                        tempCell.Text = "(" + i + "," + j + ")";

                // Apply the TableItemStyle to all rows in the table.
                foreach (TableRow r in Table1.Rows)
                    foreach (TableCell c in r.Cells)

                // Create a header for the table.
                TableHeaderCell header = new TableHeaderCell();
                header.RowSpan = 1;
                header.ColumnSpan = 3;
                header.Text = "Table of (x,y) Values";
                header.Font.Bold = true;
                header.BackColor = Color.Gray;
                header.HorizontalAlign = HorizontalAlign.Center;
                header.VerticalAlign = VerticalAlign.Middle;

                // Add the header to a new row.
                TableRow headerRow = new TableRow();

                // Add the header row to the table.
                Table1.Rows.AddAt(0, headerRow);  

        <form runat="server">
            <h1>TableCell Example</h1>
            <asp:table id="Table1" runat="server" CellPadding="3" CellSpacing="3">
                    <asp:TableCell Text="(0,0)"></asp:TableCell>
                    <asp:TableCell Text="(0,1)"></asp:TableCell>
                    <asp:TableCell Text="(0,2)"></asp:TableCell>
                    <asp:TableCell Text="(1,0)"></asp:TableCell>
                    <asp:TableCell Text="(1,1)"></asp:TableCell>
                    <asp:TableCell Text="(1,2)"></asp:TableCell>

  • 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.

         Derived Classes

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

Community Additions