Back

Adding Rows and Columns to a Table Control in ASP.net/C#

  1. To Add a cell to a table first create a instance of TableCell class and add controls or assign text which is to be displayed in the cell and add the resulting cell to the TableRow() object.

    eg.
    TableCell cell=new TableCell();
    cell.Text="Cell Text"; //Add text 'cell text' in the cell
    TableRow row=new TableRow();
    row.Cells.Add(cell); //Add the above cell to a table row.
      
  2. To add a row first create an instance of TableRow class and add cells to the TableRow object and then add the Rowobject to the TableClass.

    eg.
    TableRow row=new TableRow();
    oTable.Rows.Add(row);
      

Note that the TableControl does not maintain ViewState so the value is not postback and preserved so the developer has to take care of this.

 

Back


Make a Comment on this Article

Your Name:
Comment: