HtmlTableRow.Cells 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得 HtmlTableCell 物件的集合,這些物件會表示 HtmlTable 控制項中列所包含的儲存格。
public:
virtual property System::Web::UI::HtmlControls::HtmlTableCellCollection ^ Cells { System::Web::UI::HtmlControls::HtmlTableCellCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
public virtual System.Web.UI.HtmlControls.HtmlTableCellCollection Cells { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Cells : System.Web.UI.HtmlControls.HtmlTableCellCollection
Public Overridable ReadOnly Property Cells As HtmlTableCellCollection
屬性值
HtmlTableCellCollection,包含 HtmlTable 控制項中列的儲存格。
- 屬性
範例
下列程式碼範例示範如何使用 Cells 集合逐一查看物件所 HtmlTableRow 代表之資料列的儲存格。 然後,儲存格會以新的內容更新。
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void Button_Click(Object sender, EventArgs e)
{
// Iterate through the rows of the table.
for (int i = 0; i <= Table1.Rows.Count - 1; i++)
{
// Iterate through the cells of a row.
for (int j = 0; j <= Table1.Rows[i].Cells.Count - 1; j++)
{
// Change the inner HTML of the cell.
Table1.Rows[i].Cells[j].InnerHtml = "Row " + i.ToString() +
", Column " + j.ToString();
}
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HtmlTableRow Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>HtmlTableRow Example</h3>
<table id="Table1"
style="border-width:1; border-color:Black"
runat="server">
<tr>
<td>
Cell 1
</td>
<td>
Cell 2
</td>
</tr>
<tr>
<td>
Cell 3
</td>
<td>
Cell 4
</td>
</tr>
</table>
<br /><br />
<input type="button"
value="Change Table Contents"
onserverclick ="Button_Click"
runat="server"/>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim i As Integer
Dim j As Integer
' Iterate through the rows of the table.
For i = 0 To Table1.Rows.Count - 1
' Iterate through the cells of a row.
For j = 0 To Table1.Rows(i).Cells.Count - 1
' Change the inner HTML of the cell.
Table1.Rows(i).Cells(j).InnerHtml = "Row " & i.ToString() & _
", Column " & j.ToString()
Next j
Next i
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HtmlTableRow Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>HtmlTableRow Example</h3>
<table id="Table1"
style="border-width:1; border-color:Black"
runat="server">
<tr>
<td>
Cell 1
</td>
<td>
Cell 2
</td>
</tr>
<tr>
<td>
Cell 3
</td>
<td>
Cell 4
</td>
</tr>
</table>
<br /><br />
<input type="button"
value="Change Table Contents"
onserverclick="Button_Click"
runat="server"/>
</form>
</body>
</html>
備註
Cells使用 集合,以程式設計方式存取 控制項中 HtmlTable 資料列的儲存格。 您可以在集合中以程式設計方式新增、移除及插入儲存格。
注意
如果資料列中沒有定義儲存格,則會傳回空白 HtmlTableCellCollection 物件。