System.Web.UI.HtmlControls Namespace HtmlTableRow Class
Returns the collection of cells in an HtmlTableRow.
Script |
[ HtmlTableCellCollection variable = ] HtmlTableRow.Cells |
This property can only be used programmatically; it cannot be set when declaring the control.
The property is read/write with no default value.
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.
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
HtmlTableRow Members Rows