TableRowCollection 类

封装 TableRow 对象的集合,这些对象表示 Table 控件中的单行。无法继承此类。

**命名空间:**System.Web.UI.WebControls
**程序集:**System.Web(在 system.web.dll 中)

语法

声明
Public NotInheritable Class TableRowCollection
    Implements IList, ICollection, IEnumerable
用法
Dim instance As TableRowCollection
public sealed class TableRowCollection : IList, ICollection, IEnumerable
public ref class TableRowCollection sealed : IList, ICollection, IEnumerable
public final class TableRowCollection implements IList, ICollection, 
    IEnumerable
public final class TableRowCollection implements IList, ICollection, 
    IEnumerable

备注

使用此类以编程方式管理 TableRow 对象集合。该类通常用于在 Table 控件中添加或移除行。

提示

Table 控件包含表示 TableRow 对象集合的 Rows 集合。每个 TableRow 表示表中的单独一行,并包含表示 TableCell 对象集合的 Cells 集合。这些 TableCell 对象表示表中的各个单元格。若要获取单个单元格,应首先从 Table 控件的 Rows 集合获取一个 TableRow。然后可以从 TableRowCells 集合获取一个 TableCell

示例

下面的示例说明如何将表示表行的 TableRow 对象用 Rows 属性添加到 Table 控件,从而以编程方式向表中添加行。

<%@ Page Language="VB" AutoEventWireup="True" %>

 <html>
 <head>
     <script runat="server">

        Sub Page_Load(sender As Object, e As EventArgs)
            ' Generate rows and cells.           
            Dim numrows As Integer = 3
            Dim numcells As Integer = 2
            Dim j As Integer
            For j = 0 To numrows - 1
                Dim r As New TableRow()
                Dim i As Integer
                For i = 0 To numcells - 1
                    Dim c As New TableCell()
                    c.Text = "row " & j.ToString() & ", cell " & i.ToString()
                    r.Cells.Add(c)
                Next i
                Table1.Rows.Add(r)
            Next j
        End Sub
        
     </script>
 </head>
 <body>
     <h3>Table Example, constructed programmatically</h3>
     <form runat=server>
         <asp:Table id="Table1"
              runat="server"/>
     </form>
 </body>
 </html>
    
<%@ Page Language="C#" AutoEventWireup="True" %>

 <html>
 <head>
     <script 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>Table Example, constructed programmatically</h3>
     <form runat=server>
         <asp:Table id="Table1"
              runat="server"/>
     </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>
   

.NET Framework 安全性

继承层次结构

System.Object
  System.Web.UI.WebControls.TableRowCollection

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

TableRowCollection 成员
System.Web.UI.WebControls 命名空间
TableRow 类
Table.Rows 属性
TableCell 类
TableRow.Cells 属性
Table 类

其他资源

Table、TableRow 和 TableCell Web 服务器控件