Export (0) Print
Expand All

TableRowCollection Class

Encapsulates a collection of TableRow objects that represent a single row in a Table control. This class cannot be inherited.

For a list of all members of this type, see TableRowCollection Members.

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

[Visual Basic]
NotInheritable Public Class TableRowCollection
   Implements IList, ICollection, IEnumerable
[C#]
public sealed class TableRowCollection : IList, ICollection,
   IEnumerable
[C++]
public __gc __sealed class TableRowCollection : public IList,
   ICollection, IEnumerable
[JScript]
public class TableRowCollection implements IList, ICollection,
   IEnumerable

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

Use this class to programmatically manage a collection of TableRow objects. This class is commonly used to add or remove rows from a Table control.

Note   A Table control contains a Rows collection that represents a collection of TableRow objects. Each TableRow represents an individual row in the table and contains a Cells collection that represents a collection of TableCell objects. These TableCell objects represent the individual cells in the table. To get an individual cell, you must first get a TableRow from the Rows collection of a Table control. You can then get a TableCell from the Cells collection of the TableRow.

Example

[Visual Basic, C#] 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.

[Visual Basic] 
<%@ 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>
    

[C#] 
<%@ 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>
    

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Web.UI.WebControls

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

Assembly: System.Web (in System.Web.dll)

See Also

TableRowCollection Members | System.Web.UI.WebControls Namespace | TableRow | Rows | TableCell | Cells | Table

Show:
© 2014 Microsoft