asp.net.ph

TableRow.Cells Property

System.Web.UI.WebControls Namespace   TableRow Class


Returns the collection of cells in a TableRow.

Syntax


Script [ TableCellCollection variable = ] TableRow.Cells

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

Property Value


variable A TableCellCollection 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 TableCell objects that represent the cells of a specified TableRow in a Table control.

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

NOTE: If there are no <asp:tablecell> elements defined for the row, an empty TableCellCollection object is returned.

Example

The following example shows use of the Cells collection to dynamically add cells to the rows of a Table control at run time.

// loop through the given number of rows

for ( int r = 0; r < numrows; r++ ) {
   // instantiate a new row
   TableRow row = new TableRow ( );

   // set backcolor for alternating rows
   if ( r%2 == 1 ) {
      row.BackColor = System.Drawing.Color.Beige;
   }
   // loop through the given number of cells

   for ( int c = 0; c < numcells; c++ ) {
      // instantiate a new row
      TableCell cell = new TableCell ( );

      // 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 );
}
  C# VB

 Show me 

See Also

TableRow 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