System.Web.UI.WebControls Namespace TableCellCollection Class
Returns the table cell at the specified index in the TableRow.Cells collection.
TableCell variable = TableRow.Cells.Item [ index ];
... or ...
TableCell variable = TableRow.Cells [ index ];
dim variable as TableCell = TableRow.Cells.Item ( index )
... or ...
dim variable as TableCell = TableRow.Cells ( index )
variable : TableCell = TableRow.Cells.Item ( index );
... or ...
variable : TableCell = TableRow.Cells ( index ); |
|
C# |
VB |
JScript |
- index
- An integer specifying the ordinal index of the table cell to return.
The TableCell control at the specified index.
Use this indexer to get a TableCell from the TableCellCollection. You can access a TableCell at a specified index by using simple array notation.
For example, if you have a TableCellCollection called myCellCollection, you can access the first element in the collection by using the following statement:
TableCell myCell = myCellCollection.Item [ 0 ];
... or ...
TableCell myCell = myCellCollection [ 0 ];
dim myCell as TableCell = myCellCollection.Item ( 0 )
... or ...
dim myCell as TableCell = myCellCollection ( 0 )
myCell : TableCell = myCellCollection.Item ( 0 );
... or ...
myCell : TableCell = myCellCollection ( 0 ); |
|
C# |
VB |
JScript |
NOTE: The collection is zero-based, meaning the first element in the collection returns an index value of 0.
The following example demonstrates how to use the indexer to retrieve a cell in the TableRow.Cells collection. The cell is then updated with new content.
// 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