程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> 關於.NET >> Web服務器控件:Table控件

Web服務器控件:Table控件

編輯:關於.NET

定義和用法

Table 控件與 TableCell 控件和 TableRow 控件配合,用於創建表格。聲明一個表並允許您以編程方式對其進行操作。

屬性

屬性 描述 .Net BackImageUrl 表格的背景圖像的 URL。 1.0 Caption 表格的標題(caption)。 2.0 CaptionAlign caption 文本的對齊方式。 2.0 CellPadding 單元格邊框與內容的間距。 1.0 CellSpacing 單元格間距。 1.0 GridLines The gridline format in the table 1.0 HorizontalAlign 表格在頁面中的水平對齊方式。 1.0 Rows 表格中的行集合。 1.0 runat 規定該控件是服務器控件。必須設置為 "server"。 1.0

Web 控件標准屬性

AccessKey, Attributes, BackColor, BorderColor, BorderStyle, BorderWidth, 
CSSClass, Enabled, Font, EnableTheming, ForeColor, Height, IsEnabled, 
SkinID, Style, TabIndex, ToolTip, Width

控件標准屬性

AppRelativeTemplateSourceDirectory, BindingContainer, ClientID, Controls, 
EnableTheming, EnableVIEwState, ID, NamingContainer, Page, Parent, Site, 
TemplateControl, TemplateSourceDirectory, UniqueID, Visible

實例

<ASP:Table
    AccessKey="string"
    BackColor="color name|#dddddd"
    BackImageUrl="uri"
    BorderColor="color name|#dddddd"
    BorderPADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px">        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"
   
    TabIndex="integer"
    ToolTip="string"
    Visible="True|False"
    Width="size"
>
            <ASP:TableFooterRow
                AccessKey="string"
                BackColor="color name|#dddddd"
                BorderColor="color name|#dddddd"
                BorderPADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px">                    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"
               
                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"
                            BorderPADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px">                                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"
                           
                            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"
                            BorderPADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px">                                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"
                           
                            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"
                BorderPADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px">                    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"
               
                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"
                            BorderPADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px">                                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"
                           
                            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"
                            BorderPADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px">                                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"
                           
                            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"
                BorderPADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px">                    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"
               
                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"
                            BorderPADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px">                                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"
                           
                            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"
                            BorderPADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px">                                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"
                           
                            TabIndex="integer"
                            Text="string"
                            ToolTip="string"
                            VerticalAlign="NotSet|Top|Middle|Bottom"
                                                        Visible="True|False"
                            Width="size"
                                                        Wrap="True|False"
                                                />
                        </ASP:TableRow>
</ASP:Table>

備注:Table 類使您可以生成 Html 表並指定其特征。可在設計時使用靜態內容生成一個表,但 Table 控件通常使用動態內容以編程方式生成。

注意:以編程方式對表行或單元格進行的添加或修改不會在發送到服務器後繼續保留。表行和單元格是其自身的控件,而不是 Table 控件的屬性。對表行或單元格進行的更改必須在向服務器進行各次發送之後重建。如果需要進行大量修改,則使用 DataList 或 DataGrid 控件來代替 Table 控件。

每個 Table 控件由存儲在該控件的 Rows 集合中的行(由 HtmlTableRow 類的實例表示)組成。每一行由存儲在每個 TableRow 的 Cells 集合中的單元格(由 HtmlTableCell 類的實例表示)組成。看到本信息說明該文是通過網頁教學(webjx.com)整理發布的,請不要刪掉!

通過設置 BackImageUrl 屬性,可在 Table 控件的背景中顯示一個圖像。默認情況下,表中的項的水平對齊方式是未設置的。如果要指定水平對齊方式,請設置 HorizontalAlignment 屬性。各個單元格之間的間距由 CellSpacing 屬性控制。通過設置 CellPadding 屬性,可指定單元格內容與單元格邊框之間的空間量。若要顯示單元格邊框,請設置 GridLines 屬性。可顯示水平線、垂直線或同時顯示這兩種線。

警告:文本在 Table 控件中顯示之前並非 HTML 編碼形式。這使得可以在文本中的 Html 標記中嵌入腳本。如果控件的值是由用戶輸入的,請務必要對輸入值進行驗證以防止出現安全漏洞。

示例

下面的代碼示例演示如何在設計時創建一個表。該表包含兩個單元格,每個單元格有兩行。

注意:下面的代碼示例使用單文件代碼模型,如果直接復制到代碼隱藏文件中,可能無法正常運行。此代碼示例必須復制到一個具有 .ASPx 擴展名的空文本文件。

Visual Basic

<%@ Page Language="VB" AutoEventWireup="True" %>
 <Html><body>
     <h3>Table example, constructed at design time</h3>
 <form runat=server>
 <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>
 </form>
 </body>
</Html>

C#

<%@ Page Language="C#" AutoEventWireup="True" %>
 <Html><body>
     <h3>Table example, constructed at design time</h3>
 <form runat=server>
 <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>
 </form>
 </body>
</Html>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved