TableRowCollection 類別

定義

封裝 TableRow 物件的集合,這個物件代表 Table 控制項中的單一資料列。 此類別無法獲得繼承。

public ref class TableRowCollection sealed : System::Collections::IList
public sealed class TableRowCollection : System.Collections.IList
type TableRowCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
Public NotInheritable Class TableRowCollection
Implements IList
繼承
TableRowCollection
實作

範例

下列範例示範如何透過 屬性,將代表資料表資料列的物件加入至 控制項 Rows ,以程式設計方式將資料列加入 TableRow 資料表 Table

<%@ 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">
    void Page_Load(Object sender, EventArgs e)
    {
        // Generate rows and cells.           
        int numRows = 3;
        int numCells = 2;
        for (int rowNum = 0; rowNum < numRows; rowNum++)
        {
            TableRow rw = new TableRow();
            for (int cellNum = 0; cellNum < numCells; cellNum++)
            {
                TableCell cel = new TableCell();
                cel.Text = String.Format(
                    "row {0}, cell {1}", rowNum, cellNum);
                rw.Cells.Add(cel);
            }
            Table1.Rows.Add(rw);
            Table1.GridLines = GridLines.Both;
            Table1.CellPadding = 4;
            Table1.CellSpacing = 0;
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Programmatic Table</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h3>Table Example, constructed programmatically</h3>
        <asp:Table id="Table1" 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(ByVal sender As Object, ByVal e As EventArgs)
        ' Generate rows and cells.           
        Dim numRows As Integer = 3
        Dim numcells As Integer = 2
        Dim rowNum As Integer
        For rowNum = 0 To numRows - 1
            Dim rw As New TableRow()
            Dim cellNum As Integer
            For cellNum = 0 To numcells - 1
                Dim cel As New TableCell()
                cel.Text = String.Format( _
                    "row {0}, cell {1}", rowNum, cellNum)
                rw.Cells.Add(cel)
            Next cellNum
            Table1.Rows.Add(rw)
        Next rowNum
        Table1.GridLines = GridLines.Both
        Table1.CellPadding = 4
        Table1.CellSpacing = 0
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Programmatic Table</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h3>Table Example, constructed programmatically</h3>
        <asp:Table id="Table1" runat="server"/>
    </div>
    </form>
</body>
</html>

<html>
<head>
    <script language="C#" runat="server">
        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.Text="row " + j.ToString() + ", cell " + i.ToString();
                    r.Cells.Add(c);
                }
                Table1.Rows.Add(r);
            }
        }
    </script>
</head>
<body>
    <h3><font face="Verdana">Table Example, constructed programmatically</font></h3>
    <form runat=server>
        <asp:Table id="Table1"
             runat="server"/>
    </form>
</body>
</html>

備註

使用此類別以程式設計方式管理 物件的集合 TableRow 。 這個類別通常用來新增或移除 控制項中的資料 Table 列。

注意

控制項 Table 包含 Rows 代表 物件集合的 TableRow 集合。 每個都 TableRow 代表資料表中的個別資料列,並包含 Cells 代表 物件集合的 TableCell 集合。 這些 TableCell 物件代表表格中的個別儲存格。 若要取得個別儲存格,您必須先從 Rows 控制項的 Table 集合取得 TableRow 。 然後,您可以從 的 TableRow 集合取得 。 CellsTableCell

屬性

Count

取得 TableRowTableRowCollection 物件的數目。

IsReadOnly

取得值,指出 TableRowCollection 是否唯讀。

IsSynchronized

取得值,指出 TableRowCollection 的存取是否為同步處理 (安全執行緒)。

Item[Int32]

從在指定的索引的 TableRow 取得 TableRowCollection

SyncRoot

取得可用來同步存取 TableRowCollection 的物件。

方法

Add(TableRow)

將指定的 TableRow 物件附加至 TableRowCollection 的結尾。

AddAt(Int32, TableRow)

將指定的 TableRow 物件加入在指定索引位置的 TableRowCollection

AddRange(TableRow[])

TableRow 物件從指定的陣列附加至集合的結尾。

Clear()

將所有 TableRow 控制項從 TableRowCollection 移除。

CopyTo(Array, Int32)

將項目從 TableRowCollection 複製到指定的 Array,從 Array 中的指定索引開始。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetEnumerator()

傳回 IEnumerator 實作的物件,包含 TableRow 中的所有 TableRowCollection 物件。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetRowIndex(TableRow)

傳回表示 TableRow 中指定 TableRowCollection 的索引值。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
Remove(TableRow)

將指定的 TableRowTableRowCollection 中移除。

RemoveAt(Int32)

TableRow 從指定索引處的 TableRowCollection 移除。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

IList.Add(Object)

將物件加入至集合。

IList.Contains(Object)

判斷指定的物件是否包含在集合中。

IList.IndexOf(Object)

搜尋指定的物件,並傳回集合中第一個符合項目之以零起始的索引。

IList.Insert(Int32, Object)

插入物件至集合中的指定索引處。

IList.IsFixedSize

如需這個成員的說明,請參閱 IsFixedSize

IList.Item[Int32]

如需這個成員的說明,請參閱 Item[Int32]

IList.Remove(Object)

從集合中移除物件。

擴充方法

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。

AsParallel(IEnumerable)

啟用查詢的平行化作業。

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryable

適用於

另請參閱