This documentation is archived and is not being maintained.

TableHeaderRow Class

Represents a heading row in a Table control.

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

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

The TableHeaderRow class represents a heading row in a Table control. This class supports displaying tables on devices with a limited screen size. On these devices, a table with many columns and rows must be rendered across multiple pages. Adding a TableHeaderRow to a Table control allows you to specify a heading row that is rendered as the first row on each page that displays a view of the table. For more information about the view formats for a table rendered on a device with a limited screen size, see Table.

A TableHeaderRow object can contain only TableCell objects. To add content to the TableHeaderRow, you must add one or more TableCell objects to the row. Then, set the Text property of each TableCell object in the row to specify the contents of each cell. Alternatively, you can add a control to a TableCell object to specify its contents.

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

The TableHeaderRow inherits properties from TableRow that allow you to control how the contents in the row are displayed. For example, you can use the HorizontalAlign and VerticalAlign properties to specify the alignment of the contents.

The following code example demonstrates the declarative syntax for creating a Table control that has a TableHeaderRow and a TableFooterRow.

<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  

<html xmlns="" >
<head id="Head1" runat="server">
    <title>TableHeaderRow-TableFooterRow Example</title>
    <form id="form1" runat="server">

    <h3>TableHeaderRow and TableFooterRow Example</h3>

    <asp:Table id="Table1" runat="server" 
        Caption="Sample Table">

        <asp:TableHeaderRow id="Table1HeaderRow" 
                Text="Col1" />
                Text="Col2" />
                Text="Col3" />

            <asp:TableCell Text="(0,0)" />
            <asp:TableCell Text="(0,1)" />
            <asp:TableCell Text="(0,2)" />

            <asp:TableCell Text="(1,0)" />
            <asp:TableCell Text="(1,1)" />
            <asp:TableCell Text="(1,2)" />

        <asp:TableFooterRow runat="server"
                Text="The footer row." />


The following code example demonstrates how to programmatically create a Table control that has a TableHeaderRow and a TableFooterRow.


The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Page Code Model.

<%@ page language="C#" %>
<%@ Import Namespace="System.Drawing" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  

<script runat="server">
    private void Page_Load(object sender, EventArgs e)
        // Add rows to the table. 
        for (int rowNum = 0; rowNum < 100; rowNum++)
            TableRow tempRow = new TableRow();
            for (int cellNum = 0; cellNum < 4; cellNum++)
                TableCell tempCell = new TableCell();
                tempCell.Text = 
                    String.Format("({0},{1})", rowNum, cellNum);

        // Create a TableHeaderRow.
        TableHeaderRow headerRow = new TableHeaderRow();
        headerRow.BackColor = Color.LightBlue;

        // Create TableCell objects to contain  
        // the text for the header.
        TableHeaderCell headerTableCell1 = new TableHeaderCell();
        TableHeaderCell headerTableCell2 = new TableHeaderCell();
        TableHeaderCell headerTableCell3 = new TableHeaderCell();
        headerTableCell1.Text = "Column 1 Header";
        headerTableCell1.Scope = TableHeaderScope.Column;
        headerTableCell1.AbbreviatedText = "Col 1 Head";
        headerTableCell2.Text = "Column 2 Header";
        headerTableCell2.Scope = TableHeaderScope.Column;
        headerTableCell2.AbbreviatedText = "Col 2 Head";
        headerTableCell3.Text = "Column 3 Header";
        headerTableCell3.Scope = TableHeaderScope.Column;
        headerTableCell3.AbbreviatedText = "Col 3 Head";

        // Add the TableHeaderCell objects to the Cells 
        // collection of the TableHeaderRow.

        // Add the TableHeaderRow as the first item  
        // in the Rows collection of the table.
        Table1.Rows.AddAt(0, headerRow);

        // Create a TableFooterRow.
        TableFooterRow footerRow = new TableFooterRow();
        footerRow.BackColor = Color.LightBlue;

        // Create TableCell objects to contain the  
        // text for the footer.
        TableCell footerTableCell1 = new TableCell();
        TableCell footerTableCell2 = new TableCell();
        TableCell footerTableCell3 = new TableCell();
        footerTableCell1.Text = "Column 1 footer";
        footerTableCell2.Text = "Column 2 footer";
        footerTableCell3.Text = "Column 3 footer";

        // Add the TableCell objects to the Cells 
        // collection of the TableFooterRow.

        // Add the TableFooterRow to the Rows 
        // collection of the table.

<html xmlns="" >
<head id="Head1" runat="server">
    <title>TableHeaderRow Example</title>
    <form id="form1" runat="server">

    <h3>TableHeaderRow and TableFooterRow Example</h3>
    <asp:table id="Table1" 


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