閱讀此文請先查看網頁教學網的:ASP.NET入門教程:Web服務器控件,簡單講述了Web服務器控件的使用方法。
Table 控件與 TableCell 控件和 TableRow 控件配合,用於創建表格。聲明一個表並允許您以編程方式對其進行操作。
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"
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>
備注: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>