TableCellCollection.AddRange Method
Assembly: System.Web (in system.web.dll)
Use the AddRange method to append the TableCell objects from the specified array to the collection. This method is commonly used when you are constructing a row of a table. To construct a row of a table, first create an array of TableCell objects to represent the cells of the row. Next, use the AddRange method, passing the array as an argument, to add the TableCell objects to the collection.
The following example demonstrates how to use the AddRange method to add the TableCell objects from an array to a TableCellCollection. Note that in the example, the Cells property of the TableRow is an instance of the TableCellCollection class.
void Page_Load(Object sender, EventArgs e)
{
int numRows = 3;
int numCells = 2;
// Create 3 rows, each containing 2 cells.
for(int i=0;i < numRows;i++) {
TableCell arrayOfTableRowCells[] = new TableCell[numCells];
TableRow myTableRow = new TableRow();
for(int j=0;j < numCells;j++) {
TableCell myTableCell = new TableCell();
myTableCell.set_Text("[Row " + System.Convert.ToString(i)
+ ", Cell " + System.Convert.ToString(j) + "]");
arrayOfTableRowCells .set_Item( j , myTableCell );
}
// Get 'TableCellCollection' associated with the 'TableRow'.
TableCellCollection myTableCellCol = myTableRow.get_Cells();
// Add a row of cells.
myTableCellCol.AddRange(arrayOfTableRowCells);
myTable.get_Rows().Add(myTableRow);
}
} //Page_Load
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.