TableRowCollection 类

定义

封装表示 Table 控件中单个行的 TableRow 对象集合。 此类不能被继承。

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 属性将表示表行的 对象添加到 控件,从而以编程方式向Table表中添加TableRow行。

<%@ 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 对象表示表中的各个单元格。 若要获取单个单元格,必须先从 控件的Table集合中Rows获取 TableRow 。 然后,可以从 的TableRow集合中Cells获取 TableCell

属性

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)

TableRow 中移除指定的 TableRowCollection

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

适用于

另请参阅