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.

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

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

'Declaration
Public NotInheritable Class TableRowCollection _
	Implements IList, ICollection, IEnumerable

The TableRowCollection type exposes the following members.

  NameDescription
Public propertyCountGets the number of TableRow objects in the TableRowCollection.
Public propertyIsReadOnlyGets a value indicating whether the TableRowCollection is read-only.
Public propertyIsSynchronizedGets a value indicating whether access to the TableRowCollection is synchronized (thread-safe).
Public propertyItemGets a TableRow from the TableRowCollection at the specified index.
Public propertySyncRootGets the object that can be used to synchronize access to the TableRowCollection.
Top

  NameDescription
Public methodAddAppends the specified TableRow object to the end of the TableRowCollection.
Public methodAddAtAdds the specified TableRow object to the TableRowCollection at the specified index location.
Public methodAddRangeAppends the TableRow objects from the specified array to the end of the collection.
Public methodClearRemoves all TableRow controls from the TableRowCollection.
Public methodCopyToCopies the items from the TableRowCollection to the specified System.Array, starting with the specified index in the System.Array.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetEnumeratorReturns a System.Collections.IEnumerator implemented object that contains all TableRow objects within the TableRowCollection.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetRowIndexReturns a value that represents the index of the specified TableRow from the TableRowCollection.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodRemoveRemoves the specified TableRow from the TableRowCollection.
Public methodRemoveAtRemoves a TableRow from the TableRowCollection at the specified index.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public Extension MethodAsParallelEnables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension MethodAsQueryableConverts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodCast(Of TResult)Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodOfType(Of TResult)Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Top

  NameDescription
Explicit interface implemetationPrivate methodIList.AddInfrastructure. Adds an object to the collection.
Explicit interface implemetationPrivate methodIList.ContainsInfrastructure. Determines whether the specified object is contained within the collection.
Explicit interface implemetationPrivate methodIList.IndexOfInfrastructure. Searches for the specified object and returns the zero-based index of the first occurrence within the collection.
Explicit interface implemetationPrivate methodIList.InsertInfrastructure. Inserts an object into the collection at the specified index.
Explicit interface implemetationPrivate propertyIList.IsFixedSizeInfrastructure. For a description of this member, see IsFixedSize.
Explicit interface implemetationPrivate propertyIList.ItemInfrastructure. For a description of this member, see Item.
Explicit interface implemetationPrivate methodIList.RemoveInfrastructure. Removes an object from the collection.
Top

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.

NoteNote

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.

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="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>
   

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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