Export (0) Print
Expand All

HtmlTableRowCollection Class

A collection of HtmlTableRow objects that represent the rows of an HtmlTable control. This class cannot be inherited.

System.Object
  System.Web.UI.HtmlControls.HtmlTableRowCollection

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

public sealed class HtmlTableRowCollection : ICollection, 
	IEnumerable

The HtmlTableRowCollection type exposes the following members.

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

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

  NameDescription
Public Extension MethodAsParallel()Overloaded. Enables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension MethodAsParallel()Overloaded. (Defined by ParallelEnumerable.)
Public Extension MethodAsQueryable()Overloaded. Converts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodAsQueryable()Overloaded. (Defined by Queryable.)
Public Extension MethodCast<TResult>()Overloaded. Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodCast<TResult>()Overloaded. (Defined by Enumerable.)
Public Extension MethodOfType<TResult>()Overloaded. Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Public Extension MethodOfType<TResult>()Overloaded. (Defined by Enumerable.)
Top

Use the HtmlTableRowCollection class to programmatically manage a collection of HtmlTableRow objects that represent the rows in an HtmlTable control. This class is commonly used to add, remove, or modify the contents of a row in an HtmlTable control.

NoteNote

An HtmlTable control contains a Rows property that represents a collection of HtmlTableRow objects. Each HtmlTableRow represents an individual row in the table. An HtmlTableRow contains a Cells property that represents a collection of HtmlTableCell objects. These objects, in turn, represent the individual cells of the table. To retrieve an individual cell, first get the HtmlTableRow object, representing the row containing the cell, from the Rows collection of the HtmlTable control. You can then get the HtmlTableCell object, representing the cell in the row, from the Cells collection of the HtmlTableRow.

The following code example demonstrates how to dynamically generate the contents of an HtmlTable control by adding rows to an HtmlTableRowCollection collection. Notice that the Rows property of a table is the HtmlTableRowCollection object.

<%@ Page Language="C#" AutoEventWireup="True" %>

 <!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)
   {

     // Get the number of rows and columns selected by the user.
     int numrows = Convert.ToInt32(Select1.Value);
     int numcells = Convert.ToInt32(Select2.Value);

     // Iterate through the rows.
     for (int j = 0; j < numrows; j++)
     {

       // Create a new row and add it to the Rows collection.
       HtmlTableRow row = new HtmlTableRow();

       // Provide a different background color for alternating rows.
       if (j % 2 == 1)
         row.BgColor = "Gray";

       // Iterate through the cells of a row.
       for (int i = 0; i < numcells; i++)
       {
         // Create a new cell and add it to the Cells collection.
         HtmlTableCell cell = new HtmlTableCell();
         cell.Controls.Add(new LiteralControl("row " +
                           j.ToString() +
                           ", cell " +
                           i.ToString()));
         row.Cells.Add(cell);
       }
       Table1.Rows.Add(row);
     }
   }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
   <title>HtmlTableRowCollection Example</title>
</head>
<body>

   <form id="form1" runat="server">

      <h3>HtmlTableRowCollection Example</h3>

      <table id="Table1" 
             style="border-width:1; border-color:Black; padding:5"
             cellspacing="0"
             runat="server" />

      <hr />

      Select the number of rows and columns to create: <br /><br />

      Table rows:
      <select id="Select1" 
              runat="server">

         <option value="1">1</option>
         <option value="2">2</option>
         <option value="3">3</option>
         <option value="4">4</option>
         <option value="5">5</option>

      </select>

      &nbsp;&nbsp;

      Table cells:
      <select id="Select2" 
              runat="server">

         <option value="1">1</option>
         <option value="2">2</option>
         <option value="3">3</option>
         <option value="4">4</option>
         <option value="5">5</option>

      </select>

      <br /><br />

      <input type="submit" 
             value="Generate Table" 
             runat="server"/>

   </form>

</body>
</html>

.NET Framework

Supported in: 4.6, 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