TableRowCollection Class

Definition

封装表示 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
Inheritance
TableRowCollection
Implements

Examples

下面的示例演示如何通过将表示表行的 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>
   

Remarks

使用此类以编程方式管理 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.

Note

Table 控件包含一个 Rows 集合,该集合表示 TableRow 对象的集合。A Table control contains a Rows collection that represents a collection of TableRow objects. 每个 TableRow 都表示表中的单个行并包含一个表示 TableCell 对象集合的 Cells 集合。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. 若要获取单个单元,必须首先从 Table 控件的 Rows 集合获取 TableRowTo get an individual cell, you must first get a TableRow from the Rows collection of a Table control. 然后,你可以从 TableRowCells 集合获取 TableCellYou can then get a TableCell from the Cells collection of the TableRow.

Properties

Count

获取 TableRowTableRowCollection 对象的数目。Gets the number of TableRow objects in the TableRowCollection.

IsReadOnly

获取一个值,该值指示 TableRowCollection 是否为只读。Gets a value indicating whether the TableRowCollection is read-only.

IsSynchronized

获取一个值,该值指示是否同步对 TableRowCollection 的访问(线程安全)。Gets a value indicating whether access to the TableRowCollection is synchronized (thread-safe).

Item[Int32]

TableRow 中获取位于指定索引位置的 TableRowCollectionGets a TableRow from the TableRowCollection at the specified index.

SyncRoot

获取可用于同步 TableRowCollection 访问的对象。Gets the object that can be used to synchronize access to the TableRowCollection.

Methods

Add(TableRow)

将指定的 TableRow 对象追加到 TableRowCollection 的结尾处。Appends the specified TableRow object to the end of the TableRowCollection.

AddAt(Int32, TableRow)

将指定的 TableRow 对象添加到 TableRowCollection 中的指定索引位置。Adds the specified TableRow object to the TableRowCollection at the specified index location.

AddRange(TableRow[])

TableRow 对象从指定的数组追加到集合的末尾。Appends the TableRow objects from the specified array to the end of the collection.

Clear()

TableRow 中移除所有 TableRowCollection 对象。Removes all TableRow controls from the TableRowCollection.

CopyTo(Array, Int32)

TableRowCollection 中的指定索引开始,将 Array 中的项复制到指定的 ArrayCopies the items from the TableRowCollection to the specified Array, starting with the specified index in the Array.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator()

返回一个实现了 IEnumerator 的对象,该对象包含 TableRow 内的所有 TableRowCollection 对象。Returns a IEnumerator implemented object that contains all TableRow objects within the TableRowCollection.

GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetRowIndex(TableRow)

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

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(TableRow)

TableRow 中移除指定的 TableRowCollectionRemoves the specified TableRow from the TableRowCollection.

RemoveAt(Int32)

TableRow 中移除位于指定索引位置的 TableRowCollectionRemoves a TableRow from the TableRowCollection at the specified index.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

IList.Add(Object)

将对象添加到集合。Adds an object to the collection.

IList.Contains(Object)

确定指定对象是否位于集合内。Determines whether the specified object is contained within the collection.

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)

将对象插入到集合中的指定索引处。Inserts an object into the collection at the specified index.

IList.IsFixedSize

有关此成员的说明,请参阅 IsFixedSizeFor a description of this member, see IsFixedSize.

IList.Item[Int32]

有关此成员的说明,请参阅 Item[Int32]For a description of this member, see Item[Int32].

IList.Remove(Object)

从集合中移除一个对象。Removes an object from the collection.

Extension Methods

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

Applies to

See also