Dynamically Add Rows and Columns to an Asp.Net Table - March 2009

The tip-of-the-month shows how to dynamically add rows and columns to an Asp.Net Table. I created an Asp.Net, VB.Net project to demonstrate how to dynamically add rows and columns to the table. The sample creates as many as 20 rows and 6 columns. In this sample 12 rows with 4 columns were created. The sample output:

Click the 'Do Again' button to create another sample.

The Default Aspx Page

The VB.Net Code

The Operative Code

Private Sub AddTableRow(ByVal iRow As Integer, ByVal oTable As Table)
    Dim oRow As New TableRow
    With oRow
        .BorderWidth = 1
        .ID =
"Row" & iRow
    End With
Private Sub AddTableColumn(ByVal sRowID As String, ByVal iRow As Integer, ByVal iCol As Integer)
Dim oCol As New TableCell
    With oCol
        .Text =
"Row " & Format(iRow, "00") & "; " & "Column " & Format(iCol, "00")
    End With
oRow As TableRow = Me.TableDynamic.FindControl(sRowID)
    If Not oRow Is Nothing Then
    End If

Download VB.Net Code

Download - VS2005 VB.Net Zipped File  Size 
Dynamic Table Project with a Solution File DynamicTableSLN.zip 23k

Previous Tip   Tip Index   Next Tip


Updated 2011/04/16