TableRowCollection TableRowCollection TableRowCollection TableRowCollection Class

定義

將表示 TableRow 控制項中單一列的 Table 物件的集合封裝。Encapsulates a collection of TableRow objects that represent a single row in a Table control. 這個類別無法被繼承。This class cannot be inherited.

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
繼承
TableRowCollectionTableRowCollectionTableRowCollectionTableRowCollection
實作

範例

下列範例示範如何以程式設計方式將資料列加入資料表加TableRow為代表資料表的資料列的物件Table透過控制Rows屬性。The following example demonstrates how to programmatically add rows to a table by adding TableRow objects, which represent the rows of the table, to the Table control through the Rows property.

<%@ 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物件。Use this class to programmatically manage a collection of TableRow objects. 這個類別常用來新增或移除資料列從Table控制項。This class is commonly used to add or remove rows from a Table control.

注意

ATable控制項包含Rows集合,表示集合TableRow物件。A Table control contains a Rows collection that represents a collection of TableRow objects. 每個TableRow代表資料表中的個別資料列,並包含Cells集合,表示集合TableCell物件。Each TableRow represents an individual row in the table and contains a Cells collection that represents a collection of TableCell objects. 這些TableCell物件代表資料表中的個別儲存格。These TableCell objects represent the individual cells in the table. 若要取得個別資料格,您必須先取得TableRowRows的集合Table控制項。To get an individual cell, you must first get a TableRow from the Rows collection of a Table control. 您可以取得TableCellCells的集合TableRowYou can then get a TableCell from the Cells collection of the TableRow.

屬性

Count Count Count Count

取得 TableRow 中的 TableRowCollection 物件數目。Gets the number of TableRow objects in the TableRowCollection.

IsReadOnly IsReadOnly IsReadOnly IsReadOnly

取得值,指出 TableRowCollection 是否唯讀。Gets a value indicating whether the TableRowCollection is read-only.

IsSynchronized IsSynchronized IsSynchronized IsSynchronized

取得表示是否同步 (Synchronize) (安全執行緒) 存取 TableRowCollection 的值。Gets a value indicating whether access to the TableRowCollection is synchronized (thread-safe).

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

從在指定的索引的 TableRow 取得 TableRowCollectionGets a TableRow from the TableRowCollection at the specified index.

SyncRoot SyncRoot SyncRoot SyncRoot

取得可用來同步存取 TableRowCollection 的物件。Gets the object that can be used to synchronize access to the TableRowCollection.

方法

Add(TableRow) Add(TableRow) Add(TableRow) Add(TableRow)

將指定的 TableRow 物件附加至 TableRowCollection 的結尾。Appends the specified TableRow object to the end of the TableRowCollection.

AddAt(Int32, TableRow) AddAt(Int32, TableRow) AddAt(Int32, TableRow) AddAt(Int32, TableRow)

將指定的 TableRow 物件加入在指定索引位置的 TableRowCollectionAdds the specified TableRow object to the TableRowCollection at the specified index location.

AddRange(TableRow[]) AddRange(TableRow[]) AddRange(TableRow[]) AddRange(TableRow[])

TableRow 物件從指定的陣列附加至集合的結尾。Appends the TableRow objects from the specified array to the end of the collection.

Clear() Clear() Clear() Clear()

將所有 TableRow 控制項從 TableRowCollection 移除。Removes all TableRow controls from the TableRowCollection.

CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32)

將項目從 TableRowCollection 複製到指定的 Array,從 Array 中的指定索引開始。Copies the items from the TableRowCollection to the specified Array, starting with the specified index in the Array.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

傳回 IEnumerator 實作的物件,包含 TableRow 中的所有 TableRowCollection 物件。Returns a IEnumerator implemented object that contains all TableRow objects within the TableRowCollection.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetRowIndex(TableRow) GetRowIndex(TableRow) GetRowIndex(TableRow) GetRowIndex(TableRow)

傳回表示 TableRow 中指定 TableRowCollection 的索引值。Returns a value that represents the index of the specified TableRow from the TableRowCollection.

GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(TableRow) Remove(TableRow) Remove(TableRow) Remove(TableRow)

將指定的 TableRowTableRowCollection 中移除。Removes the specified TableRow from the TableRowCollection.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

TableRow 從指定索引處的 TableRowCollection 移除。Removes a TableRow from the TableRowCollection at the specified index.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

明確介面實作

IList.Add(Object) IList.Add(Object) IList.Add(Object) IList.Add(Object)

將物件加入至集合。Adds an object to the collection.

IList.Contains(Object) IList.Contains(Object) IList.Contains(Object) IList.Contains(Object)

判斷指定的物件是否包含在集合中。Determines whether the specified object is contained within the collection.

IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object) IList.IndexOf(Object)

搜尋指定的物件,並傳回集合中第一個符合項目之以零起始的索引。Searches for the specified object and returns the zero-based index of the first occurrence within the collection.

IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object) IList.Insert(Int32, Object)

插入物件至集合中的指定索引處。Inserts an object into the collection at the specified index.

IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize IList.IsFixedSize

如需這個成員的說明,請參閱 IsFixedSizeFor a description of this member, see IsFixedSize.

IList.Item[Int32] IList.Item[Int32] IList.Item[Int32] IList.Item[Int32]

如需這個成員的說明,請參閱 Item[Int32]For a description of this member, see Item[Int32].

IList.Remove(Object) IList.Remove(Object) IList.Remove(Object) IList.Remove(Object)

從集合移除物件。Removes an object from the collection.

Extension Methods

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

啟用查詢的平行化作業。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

將轉換IEnumerableIQueryableConverts an IEnumerable to an IQueryable.

適用於

另請參閱