System.Web.UI.WebControls Namespace TableCellCollection Class
Returns the number of table cell objects in the TableRow.Cells collection.
Script |
[ integer intVar = ] Cells.Count |
This property can only be used programmatically; it cannot be set when declaring the control.
intVar |
Integer object representing the number of cells in the collection. |
The property is read-only with no default value.
Use the Count property to determine the number of TableCell objects contained in a TableCellCollection. Count is commonly used when iterating through the cells of a table row to determine the upper bound of a loop.
The following example demonstrates how to use the Count property to determine the number of cells in a given row of a Table. This value is then used as the upper bound of a loop to iterate through the cells of the row.
// iterate through the rows of the table
for ( int r = 0; r < myTable.Rows.Count; r++ ) {
// iterate through the cells of a row
for ( int c = 0; c < myTable.Rows [ r ].Cells.Count; c++ ) {
// change the content of each cell
myTable.Rows [ r ].Cells [ c ].InnerHtml = "Row " + r.ToString ( ) + ", Column " + c.ToString ( );
}
}
' iterate through the rows of the table
Dim r As Integer
For r = 0 To myTable.Rows.Count - 1
' iterate through the cells of a row
Dim c As Integer
For c = 0 To myTable.Rows ( r ).Cells.Count - 1
' change the content of each cell
myTable.Rows ( r ).Cells ( c ).InnerHtml = "Row " & r.ToString ( ) & ", Column " & c.ToString ( )
Next c
Next r |
|
C# |
VB |
TableCellCollection Members