Freigeben über


Table Web Server Control Declarative Syntax

Declares a table and allows you to manipulate it programmatically.

<asp:Table
    AccessKey="string"
    BackColor="color name|#dddddd"
    BackImageUrl="uri"
    BorderColor="color name|#dddddd"
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
        Inset|Outset"
    BorderWidth="size"
    Caption="string"
    CaptionAlign="NotSet|Top|Bottom|Left|Right"
    CellPadding="integer"
    CellSpacing="integer"
    CssClass="string"
    Enabled="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    Font-Bold="True|False"
    Font-Italic="True|False"
    Font-Names="string"
    Font-Overline="True|False"
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
        Large|X-Large|XX-Large"
    Font-Strikeout="True|False"
    Font-Underline="True|False"
    ForeColor="color name|#dddddd"
    GridLines="None|Horizontal|Vertical|Both"
    Height="size"
    HorizontalAlign="NotSet|Left|Center|Right|Justify"
    ID="string"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    runat="server"
    SkinID="string"
    Style="string"
    TabIndex="integer"
    ToolTip="string"
    Visible="True|False"
    Width="size"
>
            <asp:TableFooterRow
                AccessKey="string"
                BackColor="color name|#dddddd"
                BorderColor="color name|#dddddd"
                BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
                    Groove|Ridge|Inset|Outset"
                BorderWidth="size"
                CssClass="string"
                Enabled="True|False"
                EnableTheming="True|False"
                EnableViewState="True|False"
                Font-Bold="True|False"
                Font-Italic="True|False"
                Font-Names="string"
                Font-Overline="True|False"
                Font-Size="string|Smaller|Larger|XX-Small|X-Small|
                    Small|Medium|Large|X-Large|XX-Large"
                Font-Strikeout="True|False"
                Font-Underline="True|False"
                ForeColor="color name|#dddddd"
                Height="size"
                HorizontalAlign="NotSet|Left|Center|Right|Justify"
                ID="string"
                OnDataBinding="DataBinding event handler"
                OnDisposed="Disposed event handler"
                OnInit="Init event handler"
                OnLoad="Load event handler"
                OnPreRender="PreRender event handler"
                OnUnload="Unload event handler"
                runat="server"
                SkinID="string"
                Style="string"
                TabIndex="integer"
                TableSection="TableHeader|TableBody|TableFooter"
                ToolTip="string"
                VerticalAlign="NotSet|Top|Middle|Bottom"
                Visible="True|False"
                Width="size"
>
                        <asp:TableCell
                            AccessKey="string"
                            AssociatedHeaderCellID="string"
                            BackColor="color name|#dddddd"
                            BorderColor="color name|#dddddd"
                            BorderStyle="NotSet|None|Dotted|Dashed|
                                Solid|Double|Groove|Ridge|Inset|
                                Outset"
                            BorderWidth="size"
                            ColumnSpan="integer"
                            CssClass="string"
                            Enabled="True|False"
                            EnableTheming="True|False"
                            EnableViewState="True|False"
                            Font-Bold="True|False"
                            Font-Italic="True|False"
                            Font-Names="string"
                            Font-Overline="True|False"
                            Font-Size="string|Smaller|Larger|
                                XX-Small|X-Small|Small|Medium|Large|
                                X-Large|XX-Large"
                            Font-Strikeout="True|False"
                            Font-Underline="True|False"
                            ForeColor="color name|#dddddd"
                            Height="size"
                            HorizontalAlign="NotSet|Left|Center|
                            Right|Justify"
                            ID="string"
                            OnDataBinding="DataBinding event handler"
                            OnDisposed="Disposed event handler"
                            OnInit="Init event handler"
                            OnLoad="Load event handler"
                            OnPreRender="PreRender event handler"
                            OnUnload="Unload event handler"
                            RowSpan="integer"
                            runat="server"
                            SkinID="string"
                            Style="string"
                            TabIndex="integer"
                            Text="string"
                            ToolTip="string"
                            VerticalAlign="NotSet|Top|Middle|Bottom"
                            Visible="True|False"
                            Width="size"
                            Wrap="True|False"
                        />
                        <asp:TableHeaderCell
                            AbbreviatedText="string"
                            AccessKey="string"
                            AssociatedHeaderCellID="string"
                            BackColor="color name|#dddddd"
                            BorderColor="color name|#dddddd"
                            BorderStyle="NotSet|None|Dotted|Dashed|
                                Solid|Double|Groove|Ridge|Inset|
                                Outset"
                            BorderWidth="size"
                            CategoryText="string"
                            ColumnSpan="integer"
                            CssClass="string"
                            Enabled="True|False"
                            EnableTheming="True|False"
                            EnableViewState="True|False"
                            Font-Bold="True|False"
                            Font-Italic="True|False"
                            Font-Names="string"
                            Font-Overline="True|False"
                            Font-Size="string|Smaller|Larger|
                                XX-Small|X-Small|Small|Medium|Large|
                                X-Large|XX-Large"
                            Font-Strikeout="True|False"
                            Font-Underline="True|False"
                            ForeColor="color name|#dddddd"
                            Height="size"
                            HorizontalAlign="NotSet|Left|Center|
                                Right|Justify"
                            ID="string"
                            OnDataBinding="DataBinding event handler"
                            OnDisposed="Disposed event handler"
                            OnInit="Init event handler"
                            OnLoad="Load event handler"
                            OnPreRender="PreRender event handler"
                            OnUnload="Unload event handler"
                            RowSpan="integer"
                            runat="server"
                            Scope="NotSet|Row|Column"
                            SkinID="string"
                            Style="string"
                            TabIndex="integer"
                            Text="string"
                            ToolTip="string"
                            VerticalAlign="NotSet|Top|Middle|Bottom"
                            Visible="True|False"
                            Width="size"
                            Wrap="True|False"
                        />
            </asp:TableFooterRow>
            <asp:TableHeaderRow
                AccessKey="string"
                BackColor="color name|#dddddd"
                BorderColor="color name|#dddddd"
                BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
                    Groove|Ridge|Inset|Outset"
                BorderWidth="size"
                CssClass="string"
                Enabled="True|False"
                EnableTheming="True|False"
                EnableViewState="True|False"
                Font-Bold="True|False"
                Font-Italic="True|False"
                Font-Names="string"
                Font-Overline="True|False"
                Font-Size="string|Smaller|Larger|XX-Small|X-Small|
                    Small|Medium|Large|X-Large|XX-Large"
                Font-Strikeout="True|False"
                Font-Underline="True|False"
                ForeColor="color name|#dddddd"
                Height="size"
                HorizontalAlign="NotSet|Left|Center|Right|Justify"
                ID="string"
                OnDataBinding="DataBinding event handler"
                OnDisposed="Disposed event handler"
                OnInit="Init event handler"
                OnLoad="Load event handler"
                OnPreRender="PreRender event handler"
                OnUnload="Unload event handler"
                runat="server"
                SkinID="string"
                Style="string"
                TabIndex="integer"
                TableSection="TableHeader|TableBody|TableFooter"
                ToolTip="string"
                VerticalAlign="NotSet|Top|Middle|Bottom"
                Visible="True|False"
                Width="size"
>
                        <asp:TableCell
                            AccessKey="string"
                            AssociatedHeaderCellID="string"
                            BackColor="color name|#dddddd"
                            BorderColor="color name|#dddddd"
                            BorderStyle="NotSet|None|Dotted|Dashed|
                                Solid|Double|Groove|Ridge|Inset|
                                Outset"
                            BorderWidth="size"
                            ColumnSpan="integer"
                            CssClass="string"
                            Enabled="True|False"
                            EnableTheming="True|False"
                            EnableViewState="True|False"
                            Font-Bold="True|False"
                            Font-Italic="True|False"
                            Font-Names="string"
                            Font-Overline="True|False"
                            Font-Size="string|Smaller|Larger|
                                XX-Small|X-Small|Small|Medium|Large|
                                X-Large|XX-Large"
                            Font-Strikeout="True|False"
                            Font-Underline="True|False"
                            ForeColor="color name|#dddddd"
                            Height="size"
                            HorizontalAlign="NotSet|Left|Center|
                                Right|Justify"
                            ID="string"
                            OnDataBinding="DataBinding event handler"
                            OnDisposed="Disposed event handler"
                            OnInit="Init event handler"
                            OnLoad="Load event handler"
                            OnPreRender="PreRender event handler"
                            OnUnload="Unload event handler"
                            RowSpan="integer"
                            runat="server"
                            SkinID="string"
                            Style="string"
                            TabIndex="integer"
                            Text="string"
                            ToolTip="string"
                            VerticalAlign="NotSet|Top|Middle|Bottom"
                            Visible="True|False"
                            Width="size"
                            Wrap="True|False"
                        />
                        <asp:TableHeaderCell
                            AbbreviatedText="string"
                            AccessKey="string"
                            AssociatedHeaderCellID="string"
                            BackColor="color name|#dddddd"
                            BorderColor="color name|#dddddd"
                            BorderStyle="NotSet|None|Dotted|Dashed|
                                Solid|Double|Groove|Ridge|Inset|
                                Outset"
                            BorderWidth="size"
                            CategoryText="string"
                            ColumnSpan="integer"
                            CssClass="string"
                            Enabled="True|False"
                            EnableTheming="True|False"
                            EnableViewState="True|False"
                            Font-Bold="True|False"
                            Font-Italic="True|False"
                            Font-Names="string"
                            Font-Overline="True|False"
                            Font-Size="string|Smaller|Larger|
                                XX-Small|X-Small|Small|Medium|Large|
                                X-Large|XX-Large"
                            Font-Strikeout="True|False"
                            Font-Underline="True|False"
                            ForeColor="color name|#dddddd"
                            Height="size"
                            HorizontalAlign="NotSet|Left|Center|
                                Right|Justify"
                            ID="string"
                            OnDataBinding="DataBinding event handler"
                            OnDisposed="Disposed event handler"
                            OnInit="Init event handler"
                            OnLoad="Load event handler"
                            OnPreRender="PreRender event handler"
                            OnUnload="Unload event handler"
                            RowSpan="integer"
                            runat="server"
                            Scope="NotSet|Row|Column"
                            SkinID="string"
                            Style="string"
                            TabIndex="integer"
                            Text="string"
                            ToolTip="string"
                            VerticalAlign="NotSet|Top|Middle|Bottom"
                            Visible="True|False"
                            Width="size"
                            Wrap="True|False"
                        />
            </asp:TableHeaderRow>
            <asp:TableRow
                AccessKey="string"
                BackColor="color name|#dddddd"
                BorderColor="color name|#dddddd"
                BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|
                    Groove|Ridge|Inset|Outset"
                BorderWidth="size"
                CssClass="string"
                Enabled="True|False"
                EnableTheming="True|False"
                EnableViewState="True|False"
                Font-Bold="True|False"
                Font-Italic="True|False"
                Font-Names="string"
                Font-Overline="True|False"
                Font-Size="string|Smaller|Larger|XX-Small|
                    X-Small|Small|Medium|Large|X-Large|XX-Large"
                Font-Strikeout="True|False"
                Font-Underline="True|False"
                ForeColor="color name|#dddddd"
                Height="size"
                HorizontalAlign="NotSet|Left|Center|Right|Justify"
                ID="string"
                OnDataBinding="DataBinding event handler"
                OnDisposed="Disposed event handler"
                OnInit="Init event handler"
                OnLoad="Load event handler"
                OnPreRender="PreRender event handler"
                OnUnload="Unload event handler"
                runat="server"
                SkinID="string"
                Style="string"
                TabIndex="integer"
                TableSection="TableHeader|TableBody|TableFooter"
                ToolTip="string"
                VerticalAlign="NotSet|Top|Middle|Bottom"
                Visible="True|False"
                Width="size"
>
                        <asp:TableCell
                            AccessKey="string"
                            AssociatedHeaderCellID="string"
                            BackColor="color name|#dddddd"
                            BorderColor="color name|#dddddd"
                            BorderStyle="NotSet|None|Dotted|Dashed|
                                Solid|Double|Groove|Ridge|Inset|
                                Outset"
                            BorderWidth="size"
                            ColumnSpan="integer"
                            CssClass="string"
                            Enabled="True|False"
                            EnableTheming="True|False"
                            EnableViewState="True|False"
                            Font-Bold="True|False"
                            Font-Italic="True|False"
                            Font-Names="string"
                            Font-Overline="True|False"
                            Font-Size="string|Smaller|Larger|
                                XX-Small|X-Small|Small|Medium|Large|
                                X-Large|XX-Large"
                            Font-Strikeout="True|False"
                            Font-Underline="True|False"
                            ForeColor="color name|#dddddd"
                            Height="size"
                            HorizontalAlign="NotSet|Left|Center|
                                Right|Justify"
                            ID="string"
                            OnDataBinding="DataBinding event handler"
                            OnDisposed="Disposed event handler"
                            OnInit="Init event handler"
                            OnLoad="Load event handler"
                            OnPreRender="PreRender event handler"
                            OnUnload="Unload event handler"
                            RowSpan="integer"
                            runat="server"
                            SkinID="string"
                            Style="string"
                            TabIndex="integer"
                            Text="string"
                            ToolTip="string"
                            VerticalAlign="NotSet|Top|Middle|Bottom"
                            Visible="True|False"
                            Width="size"
                            Wrap="True|False"
                        />
                        <asp:TableHeaderCell
                            AbbreviatedText="string"
                            AccessKey="string"
                            AssociatedHeaderCellID="string"
                            BackColor="color name|#dddddd"
                            BorderColor="color name|#dddddd"
                            BorderStyle="NotSet|None|Dotted|Dashed|
                                Solid|Double|Groove|Ridge|Inset|
                                Outset"
                            BorderWidth="size"
                            CategoryText="string"
                            ColumnSpan="integer"
                            CssClass="string"
                            Enabled="True|False"
                            EnableTheming="True|False"
                            EnableViewState="True|False"
                            Font-Bold="True|False"
                            Font-Italic="True|False"
                            Font-Names="string"
                            Font-Overline="True|False"
                            Font-Size="string|Smaller|Larger|
                                XX-Small|X-Small|Small|Medium|Large|
                                X-Large|XX-Large"
                            Font-Strikeout="True|False"
                            Font-Underline="True|False"
                            ForeColor="color name|#dddddd"
                            Height="size"
                            HorizontalAlign="NotSet|Left|Center|
                                Right|Justify"
                            ID="string"
                            OnDataBinding="DataBinding event handler"
                            OnDisposed="Disposed event handler"
                            OnInit="Init event handler"
                            OnLoad="Load event handler"
                            OnPreRender="PreRender event handler"
                            OnUnload="Unload event handler"
                            RowSpan="integer"
                            runat="server"
                            Scope="NotSet|Row|Column"
                            SkinID="string"
                            Style="string"
                            TabIndex="integer"
                            Text="string"
                            ToolTip="string"
                            VerticalAlign="NotSet|Top|Middle|Bottom"
                                                        Visible="True|False"
                            Width="size"
                                                        Wrap="True|False"
                                                />
                        </asp:TableRow>
</asp:Table>

Remarks

The Table class allows you to build an HTML table and specify its characteristics. A table can be built at design time with static content, but the Table control is often built programmatically with dynamic contents.

Note

Programmatic additions or modifications to a table row or cell will not persist across posts to the server. Table rows and cells are controls of their own, not properties of the Table control. Changes to table rows or cells must be reconstructed after each post to the server. If substantial modifications are expected, use the DataList or DataGrid controls instead of the Table control.

Each Table control is made up of rows (represented by instances of the HtmlTableRow class) stored in the Rows collection of the control. Each row is made up of cells (represented by instances of the HtmlTableCell class) stored in the Cells collection of the each TableRow.

You can display an image in the background of the Table control by setting the BackImageUrl property. By default, the horizontal alignment of the items in the table is not set. If you want to specify the horizontal alignment, set the HorizontalAlignment property. The spacing between individual cells is controlled by the CellSpacing property. You can specify the amount of space between the contents of a cell and the cell's border by setting the CellPadding property. To display the cell borders, set the GridLines property. You can display the horizontal lines, vertical lines, or both horizontal and vertical lines.

Warning

Text is not HTML encoded before it is displayed in the Table control. This makes it possible to embed script within HTML tags in the text. If the values for the control come from user input, be sure to validate the values to help prevent security vulnerabilities.

For detailed information on the Table Web server control's properties and events, see the Table class documentation.

Example

The following code example demonstrates how to create a table at design time. The table contains two rows of two cells each.

Note

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Table Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h3>Table example, constructed at design time</h3>
    <asp:Table id="Table1" runat="server"
        CellPadding="10" 
        GridLines="Both"
        HorizontalAlign="Center">
        <asp:TableRow>
            <asp:TableCell>
                Row 0, Col 0
            </asp:TableCell>
            <asp:TableCell>
                Row 0, Col 1
            </asp:TableCell>
        </asp:TableRow>
        <asp:TableRow>
            <asp:TableCell>
                Row 1, Col 0
            </asp:TableCell>
            <asp:TableCell>
                Row 1, Col 1
            </asp:TableCell>
        </asp:TableRow>
    </asp:Table>

    </div>
    </form>
</body>
</html>
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h3>Table example, constructed at design time</h3>
    <asp:Table id="Table1" runat="server"
        CellPadding="10" 
        GridLines="Both"
        HorizontalAlign="Center">
        <asp:TableRow>
            <asp:TableCell>
                Row 0, Col 0
            </asp:TableCell>
            <asp:TableCell>
                Row 0, Col 1
            </asp:TableCell>
        </asp:TableRow>
        <asp:TableRow>
            <asp:TableCell>
                Row 1, Col 0
            </asp:TableCell>
            <asp:TableCell>
                Row 1, Col 1
            </asp:TableCell>
        </asp:TableRow>
    </asp:Table>
    
    </div>
    </form>
</body>
</html>

See Also

Reference

TableCell Web Server Control Declarative Syntax
TableRow Web Server Control Declarative Syntax
Table

Other Resources

Web Server Control Syntax