Condividi tramite


Sintassi dichiarativa per il controllo server Web Table

Aggiornamento: novembre 2007

Dichiara una tabella e consente di modificarla a livello di codice.

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

Note

La classe Table consente di generare una tabella HTML e di specificarne le caratteristiche. In fase di progettazione è possibile generare una tabella con contenuto statico, ma il controllo Table viene spesso creato a livello di codice con contenuti dinamici.

Nota

Le aggiunte o le modifiche a livello di codice di una riga o di una cella di tabella non verranno rese permanenti durante l'invio al server. Le righe e le celle di tabella sono controlli, non proprietà del controllo Table. Le modifiche apportate alle righe o alle celle della tabella devono essere nuovamente eseguite dopo ogni invio al server. Se si prevedono modifiche sostanziali, utilizzare i controlli DataList o DataGrid al posto del controllo Table.

Ogni controllo Table si compone di righe, rappresentate da istanze della classe HtmlTableRow e memorizzate nell'insieme Rows del controllo. Ogni riga è costituita da celle, rappresentate da istanze della classe HtmlTableCell e memorizzate nell'insieme Cells di ciascun TableRow.

Se si imposta la proprietà BackImageUrl, è possibile visualizzare un'immagine sullo sfondo del controllo Table. Per impostazione predefinita, l'allineamento orizzontale degli elementi nella tabella non è impostato. Se si desidera specificare l'allineamento orizzontale, impostare la proprietà HorizontalAlignment. La spaziatura tra le singole celle viene controllata dalla proprietà CellSpacing. Impostare la proprietà CellPadding per specificare la spaziatura fra il contenuto di una cella e il rispettivo bordo. Per visualizzare i bordi di cella, impostare la proprietà GridLines. È possibile visualizzare le linee orizzontali, quelle verticali o entrambe.

Attenzione:

Il testo non viene codificato in formato HTML prima di essere visualizzato nel controllo Table. È pertanto possibile incorporare script all'interno dei tag HTML presenti nel testo. Se i valori del controllo provengono dall'input dell'utente, assicurarsi di convalidare tali valori per evitare problemi di protezione.

Per informazioni dettagliate sulle proprietà e sugli eventi del controllo server Web Table, vedere la documentazione relativa alla classe Table.

Esempio

Nell'esempio di codice riportato di seguito viene illustrato come creare una tabella in fase di progettazione. La tabella contiene due righe, ognuna costituita da due celle.

Nota

Nell'esempio di codice riportato di seguito viene utilizzato il modello di codice a file singolo e se viene copiato direttamente in un file code-behind, il codice potrebbe non funzionare. È necessario copiare l'esempio di codice in un file di testo vuoto con estensione aspx. Per ulteriori informazioni sul modello di codice di Web Form, vedere Modello di codice di pagine 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>

Vedere anche

Riferimenti

Table

Sintassi dichiarativa per il controllo server Web TableCell

Sintassi dichiarativa per il controllo server Web TableRow

Altre risorse

Sintassi dei controlli server Web