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