閱讀此文請先查看網頁教學網的:ASP.NET入門教程:Web服務器控件,簡單講述了Web服務器控件的使用方法。
TableRow 控件與 TableCell 控件和 Table 控件一起使用,來創建表格中的行。表示 Table 控件中的行並允許您以編程方式對其進行操作。
提示:表格的行存儲在 Table 控件中的 Rows 集合中。
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: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>
備注:TableRow 類的實例表示 Table 控件中的行。表中的行存儲在 Table 控件的 Rows 集合中。
此類使您可以控制行內容的顯示方式。設置 HorizontalAlign 和 VerticalAlign 屬性可以分別指定行中內容的水平和垂直對齊方式。
行中的單元格(由 TableCell 類的實例表示)存儲在表示該行的 TableRow 的 Cells 集合中。使用 Cells 集合可以通過編程方式管理行中的單元格。
下面的示例演示如何使用 TableRow 對象向 Table 控件添加行。
Visual Basic
<%@ Page language="VB" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>
<html>
<head>
<script runat="server">
Private Sub Page_Load(sender As Object, e As System.EventArgs)
' Create a TableItemStyle object that can be
' set as the default style for all cells
' in the table.
Dim tableStyle As New TableItemStyle()
tableStyle.HorizontalAlign = HorizontalAlign.Center
tableStyle.VerticalAlign = VerticalAlign.Middle
tableStyle.Width = Unit.Pixel(100)
' Create more rows for the table.
Dim i As Integer
For i = 2 To 9
Dim tempRow As New TableRow()
Dim j As Integer
For j = 0 To 2
Dim tempCell As New TableCell()
tempCell.Text = "(" & i & "," & j & ")"
tempRow.Cells.Add(tempCell)
Next j
Table1.Rows.Add(tempRow)
Next i
' Apply the TableItemStyle to all rows in the table.
Dim r As TableRow
For Each r In Table1.Rows
Dim c As TableCell
For Each c In r.Cells
c.ApplyStyle(tableStyle)
Next c
Next r
' Create a header for the table.
Dim header As New TableHeaderCell()
header.RowSpan = 1
header.ColumnSpan = 3
header.Text = "Table of (x,y) Values"
header.Font.Bold = true
header.BackColor = Color.Gray
header.HorizontalAlign = HorizontalAlign.Center
header.VerticalAlign = VerticalAlign.Middle
' Add the header to a new row.
Dim headerRow As New TableRow()
headerRow.Cells.Add(header)
' Add the header row to the table.
Table1.Rows.AddAt(0, headerRow)
End Sub
</script>
</head>
<body>
<form runat="server">
<h1>TableCell Example</h1>
<asp:table id="Table1" runat="server" CellPadding="3" CellSpacing="3">
<asp:TableRow>
<asp:TableCell Text="(0,0)"></asp:TableCell>
<asp:TableCell Text="(0,1)"></asp:TableCell>
<asp:TableCell Text="(0,2)"></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell Text="(1,0)"></asp:TableCell>
<asp:TableCell Text="(1,1)"></asp:TableCell>
<asp:TableCell Text="(1,2)"></asp:TableCell>
</asp:TableRow>
</asp:table>
</form>
</body>
</html>
C#
<%@ Page language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>
<html>
<head>
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
// Create a TableItemStyle object that can be
// set as the default style for all cells
// in the table.
TableItemStyle tableStyle = new TableItemStyle();
tableStyle.HorizontalAlign = HorizontalAlign.Center;
tableStyle.VerticalAlign = VerticalAlign.Middle;
tableStyle.Width = Unit.Pixel(100);
// Create more rows for the table.
for (int i = 2; i < 10; i++)
{
TableRow tempRow = new TableRow();
for (int j = 0; j < 3; j++)
{
TableCell tempCell = new TableCell();
tempCell.Text = "(" + i + "," + j + ")";
tempRow.Cells.Add(tempCell);
}
Table1.Rows.Add(tempRow);
}
// Apply the TableItemStyle to all rows in the table.
foreach (TableRow r in Table1.Rows)
foreach (TableCell c in r.Cells)
c.ApplyStyle(tableStyle);
// Create a header for the table.
TableHeaderCell header = new TableHeaderCell();
header.RowSpan = 1;
header.ColumnSpan = 3;
header.Text = "Table of (x,y) Values";
header.Font.Bold = true;
header.BackColor = Color.Gray;
header.HorizontalAlign = HorizontalAlign.Center;
header.VerticalAlign = VerticalAlign.Middle;
// Add the header to a new row.
TableRow headerRow = new TableRow();
headerRow.Cells.Add(header);
// Add the header row to the table.
Table1.Rows.AddAt(0, headerRow);
}
</script>
</head>
<body>
<form runat="server">
<h1>TableCell Example</h1>
<asp:table id="Table1" runat="server" CellPadding="3" CellSpacing="3">
<asp:TableRow>
<asp:TableCell Text="(0,0)"></asp:TableCell>
<asp:TableCell Text="(0,1)"></asp:TableCell>
<asp:TableCell Text="(0,2)"></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell Text="(1,0)"></asp:TableCell>
<asp:TableCell Text="(1,1)"></asp:TableCell>
<asp:TableCell Text="(1,2)"></asp:TableCell>
</asp:TableRow>
</asp:table>
</form>
</body>
</html>