Partager via


Syntaxe déclarative du contrôle serveur Web Table

Mise à jour : novembre 2007

Déclare un tableau et vous permet de le manipuler par programme.

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

Notes

La classe Table permet de générer un tableau HTML et de spécifier ses caractéristiques. Il est possible de générer un tableau au moment du design avec du contenu statique, mais le contrôle Table est souvent créé par programme avec du contenu dynamique.

Remarque :

Les ajouts ou les modifications apportés par programme à une cellule ou à une ligne de tableau ne seront pas rendus persistants pendant les publications sur le serveur. Les lignes et les cellules du tableau sont des contrôles en soi et non des propriétés du contrôle Table. Les modifications apportées aux cellules ou aux lignes du tableau doivent être reconstruites après chaque publication sur le serveur. Si vous prévoyez des modifications importantes, utilisez les contrôles DataList ou DataGrid à la place du contrôle Table.

Chaque contrôle Table est composé de lignes (représentées par des instances de la classe HtmlTableRow) stockées dans la collection Rows du contrôle. Chaque ligne est composée de cellules (représentées par des instances de la classe HtmlTableCell) stockées dans la collection Cells de chaque TableRow.

Vous pouvez afficher une image dans l'arrière-plan du contrôle Table en définissant la propriété BackImageUrl. Par défaut, l'alignement horizontal des éléments du tableau n'est pas défini. Si vous souhaitez spécifier l'alignement horizontal, définissez la propriété HorizontalAlignment. L'espace entre chaque cellule est contrôlé par la propriété CellSpacing. Vous pouvez spécifier l'espace entre le contenu d'une cellule et sa bordure en définissant la propriété CellPadding. Pour afficher les bordures des cellules, définissez la propriété GridLines. Vous pouvez afficher les lignes horizontales, les lignes verticales ou les deux.

Attention :

Le texte n'est pas codé au format HTML avant d'être affiché dans le contrôle Table. Il est ainsi possible d'incorporer du script dans les balises HTML dans le texte. Si les valeurs du contrôle proviennent des entrées d'utilisateur, veillez à valider les valeurs pour permettre d'empêcher les failles en matière de sécurité.

Pour plus d'informations sur les propriétés et événements du contrôle serveur Web Table, consultez la documentation de la classe Table.

Exemple

L'exemple de code suivant illustre la création d'un tableau au moment du design. Le tableau comporte deux lignes de deux cellules chacune.

Remarque :

L'exemple de code suivant utilise un modèle de code à fichier unique ; il est possible qu'il ne fonctionne pas correctement s'il est directement copié dans un fichier code-behind. Cet exemple de code doit être copié dans un fichier texte vide doté d'une extension .aspx. Pour plus d'informations sur le modèle de code Web Forms, consultez Modèle de code des pages Web ASP.NET.

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

Voir aussi

Référence

Table

Syntaxe déclarative du contrôle serveur Web TableCell

Syntaxe déclarative du contrôle serveur Web TableRow

Autres ressources

Syntaxe des contrôles serveur Web