asp.net.ph

HtmlTableRow.Cells Property

System.Web.UI.HtmlControls Namespace   HtmlTableRow Class


Returns the collection of cells in an HtmlTableRow.

Syntax


Script [ HtmlTableCellCollection variable = ] HtmlTableRow.Cells

This property can only be used programmatically; it cannot be set when declaring the control.

Property Value


variable An HtmlTableCellCollection object that represents the cells in a given table row.

The property is read/write with no default value.

Remarks

Use the Cells collection to programmatically access the HtmlTableCell objects that represent the cells of a specified HtmlTableRow in an HtmlTable control.

Using this property, you can dynamically add to, remove from, and loop thru each element in the Cells collection.

If there are no <th> or <td> elements defined for the row, an empty HtmlTableCellCollection object is returned.

Example

The following example shows use of the Cells collection to dynamically add cells to the rows of an HtmlTable.

// loop through the given number of rows
for ( int r = 0; r < numrows; r++ ) {
   // instantiate a new row
   HtmlTableRow row = new HtmlTableRow ( );

   // set bgcolor for alternating rows
   if ( r%2 == 1 ) row.BgColor = "beige";

   // loop through the given number of cells
   for ( int c = 0; c < numcells; c++ ) {
      // instantiate a new cell
      HtmlTableCell cell = new HtmlTableCell ( );

      // add cell content
      cell.Controls.Add ( new LiteralControl ( "row " + r.ToString ( ) + 
         ", cell " + c.ToString ( ) ) );

      // add the cell to the Cells collection
      row.Cells.Add ( cell );
   }
   // add the row to the Rows collection
   myTable.Rows.Add ( row );
}

 Show me 

See Also

HtmlTableRow Members   Rows Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph