asp.net.ph

TableRowCollection.Add Method

System.Web.UI.WebControls Namespace   TableRowCollection Class


Appends a new row to a Table.

[ VB ]
Public Sub Add ( _
   ByVal row As TableRow _
) As Integer

[ C# ]
public int Add (
   TableRow row
);

[ C++ ]
public: int Add (
   TableRow* row
);

[ JScript ]
public function Add (
   row : TableRow
) : int;

Parameters

row
The TableRow to add to the collection.

Return Value

The index number of the TableRow.

Remarks

Use this method to add the specified TableRow to the end of a TableRowCollection. If you need to insert a TableRow at a specific location in the collection, use the AddAt method.

Example

The following example shows use of the Add method to programmatically append a row to a Table control at run time.

// loop through the given number of rows

for ( int r = 0; r < numrows; r++ ) {
   // instantiate a new row
   TableRow row = new TableRow ( );

   // set backcolor for alternating rows
   if ( r%2 == 1 ) {
      row.BackColor = System.Drawing.Color.Beige;
   }
   // loop through the given number of cells

   for ( int c = 0; c < numcells; c++ ) {
      // instantiate a new row
      TableCell cell = new TableCell ( );

      // 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 );
}
  C# VB

 Show me 

See Also

TableRowCollection Members   Rows.AddAt   Rows.AddRange   Rows.Remove   Rows.RemoveAt   Rows.Clear Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph