System.Web.UI.HtmlControls Namespace HtmlTable Class
Returns the collection of rows in an HtmlTable.
Script |
[ HtmlTableRowCollection variable = ] HtmlTable.Rows |
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 Rows collection to programmatically access the rows in a given HtmlTable. Like any collection in ASP.NET, you can dynamically add rows to, remove rows from, and loop thru the rows in, the collection.
If no <tr> elements are defined for the table, an empty HtmlTableRowCollection object is returned.
The following example shows use of the Rows collection to dynamically add rows to 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
HtmlTable Members Cells