Table.Rows 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在控制中取得列的集合 Table 。
public:
virtual property System::Web::UI::WebControls::TableRowCollection ^ Rows { System::Web::UI::WebControls::TableRowCollection ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerDefaultProperty)]
public virtual System.Web.UI.WebControls.TableRowCollection Rows { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerDefaultProperty)>]
member this.Rows : System.Web.UI.WebControls.TableRowCollection
Public Overridable ReadOnly Property Rows As TableRowCollection
屬性值
TableRowCollection A 包含TableRow控制項中的Table物件。
- 屬性
範例
以下範例示範如何利用該 Rows 集合程式化建構資料表。 動態建立資料表包含三個步驟。 首先,建立 TableCell 物件來代表排成一列的儲存格。 儲存格的內容可透過設定Text屬性或在集合中新增控制Control.ControlsTableCell項來增加。 接著,建立一個 TableRow 來表示表格中的一列。 將先前Cells建立的TableCell物件加入 的集合TableRow中。 最後,將 加入TableRowRows控制組Table集合。 對表格中的每一列重複這個過程。
備註
以下程式碼範例採用單檔案程式碼模型,若直接複製到程式碼背後的檔案中,可能無法正常運作。 此程式碼範例必須複製到一個副檔名為an. aspx的空文字檔中。 欲了解更多關於網頁表單程式碼模型的資訊,請參見 ASP.NET 網頁表單頁面程式碼模型。
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
private void Page_Load(Object sender, EventArgs e)
{
// Generate rows and cells.
int numrows = 3;
int numcells = 2;
for (int j = 0; j < numrows; j++)
{
TableRow r = new TableRow();
for (int i = 0; i < numcells; i++) {
TableCell c = new TableCell();
c.Controls.Add(new LiteralControl("row "
+ j.ToString() + ", cell " + i.ToString()));
r.Cells.Add(c);
}
Table1.Rows.Add(r);
}
}
</script>
<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 programmatically</h3>
<asp:Table id="Table1"
GridLines="Both"
HorizontalAlign="Center"
Font-Names="Verdana"
Font-Size="8pt"
CellPadding="15"
CellSpacing="0"
Runat="server"/>
</div>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
' Generate rows and cells.
Dim numrows As Integer = 3
Dim numcells As Integer = 2
Dim j As Integer
For j = 0 To numrows - 1
Dim r As New TableRow()
Dim i As Integer
For i = 0 To numcells - 1
Dim c As New TableCell()
c.Controls.Add(New LiteralControl("row " & j.ToString() & ", cell " & i.ToString()))
r.Cells.Add(c)
Next i
Table1.Rows.Add(r)
Next j
End Sub 'Page_Load
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Programmatic Table Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Table Example, constructed programmatically</h3>
<asp:Table id="Table1"
GridLines="Both"
HorizontalAlign="Center"
Font-Names="Verdana"
Font-Size="8pt"
CellPadding="15"
CellSpacing="0"
Runat="server"/>
</div>
</form>
</body>
</html>
備註
使用集合 Rows 來程式化管理 TableRow 控制中的 Table 物件。 A TableRow 代表表格中的一列。