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:
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?
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?