Dynamiclly adding rows and cells in a table in .net 2.0

Joined
Jan 19, 2010
Messages
2
Reaction score
0
I'm new at programming in .net.
I'm trying to dynamiclly adding rows and cells in a table.
After searching the webb for examples and finally finding one at MSDN. I came up with this (non working) code:
Code:
Dim tableStyle As New TableItemStyle()
        tableStyle.HorizontalAlign = HorizontalAlign.Center
        tableStyle.VerticalAlign = VerticalAlign.Middle
        tableStyle.Width = 100%

        ' Create more rows for the table.
        Dim rowNum As Integer
        For rowNum = 3 To CInt(AntMaskor) / 2 + 2
            Dim tempRow As New TableRow()
            Dim cellNum As Integer
            For cellNum = 0 To 2
                Dim tempCell As New TableCell()
                tempCell.Text = String.Format("({0},{1})", rowNum, cellNum)
                tempRow.Cells.Add(tempCell)
            Next
            TableDynamic.Rows.Add(tempRow)
        Next

        ' Apply the TableItemStyle to all rows in the table.
        Dim rw As TableRow
        For Each rw In TableDynamic.Rows
            Dim cel As TableCell
            For Each cel In rw.Cells
                cel.ApplyStyle(tableStyle)
            Next
        Next

        ' Create a header for the table.
        Dim header As New TableHeaderCell()
        header.RowSpan = 1
        header.ColumnSpan = 1
        header.Text = "Mätn:"
        header.Font.Bold = True
        header.BackColor = Drawing.Color.Yellow
        header.HorizontalAlign = HorizontalAlign.Center
        header.VerticalAlign = VerticalAlign.Middle

        ' Add the header to a new row.
        Dim headerRow As New TableRow()
        headerRow.Cells.Add(header)

        header.ColumnSpan = 2
        header.Text = "Maskvidd"
        header.Font.Bold = True
        header.BackColor = Drawing.Color.Yellow
        header.HorizontalAlign = HorizontalAlign.Center
        header.VerticalAlign = VerticalAlign.Middle
        headerRow.Cells.Add(header)

        header.ColumnSpan = 1
        header.Text = "Matn:"
        header.Font.Bold = True
        header.BackColor = Drawing.Color.Yellow
        header.HorizontalAlign = HorizontalAlign.Center
        header.VerticalAlign = VerticalAlign.Middle
        headerRow.Cells.Add(header)

        header.ColumnSpan = 2
        header.Text = "Maskvidd"
        header.Font.Bold = True
        header.BackColor = Drawing.Color.Yellow
        header.HorizontalAlign = HorizontalAlign.Center
        header.VerticalAlign = VerticalAlign.Middle
        headerRow.Cells.Add(header)

        header.ColumnSpan = 1
        header.Text = "Matn:"
        header.Font.Bold = True
        header.BackColor = Drawing.Color.Yellow
        header.HorizontalAlign = HorizontalAlign.Center
        header.VerticalAlign = VerticalAlign.Middle
        headerRow.Cells.Add(header)

        header.ColumnSpan = 2
        header.Text = "Trad"
        header.Font.Bold = True
        header.BackColor = Drawing.Color.Yellow
        header.HorizontalAlign = HorizontalAlign.Center
        header.VerticalAlign = VerticalAlign.Middle
        headerRow.Cells.Add(header)

        ' Add the header row to the table.
        TableDynamic.Rows.AddAt(0, headerRow)

I'm working on the header cells right now, the rows and cells in the body are same as in the example in the link.

The problem I have is that I only get one header column, but I want to have 8 columns in the table and 6 header columns.
Is there any way to have 8 columns in the header or do I have to write the code as static code in the table server control?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top