
Would like to create an ASP.net table in the form of an NFL Squares Pool through code behind.
With the sample image above and using VB.Net.
In my database I have a table titled Game, Square and SquareDetail. I have a web form titled Squares.
Through code behind I would like to dynamically create a table on my form and fill it with data from the Squares and SquaresDetails Tables.
Column and Row Headers to contain the following from the Squares Table.
x_position (string) - as column headers where initial display values will = a "?".
y_position (string) - as row headers where initial display values will = a "?".
Each inside Cell filled with the following:
gameId - invisble
A checkbox control
memberId (int) - displaying the User Name after the checkbox control is selected.
x_Value (string) with a default value = a "?"
y_Value (string) with a default value = a "?"
x and y values to be separated by a : (colon)
After all squares have been chosen the site admin will click a Button control and generate in random order the values 0-9 for each Column Header and each Row Header. Thereafter each inside cell to reflect the value of each Column and Row Header
What I need help with is generating the table by creating the Column and Row Headers with required fields in each cell.
I can handle the Button Control and random numbering and converting the memberId to display the User Name.
My code below is my feeble attempt that unfortunately renders a Question mark (?) in 11 columns and 10 rows with each inner cell containing the same Qusestion Mark and nothing like what I'm looking for in the above sample image.
I hope I explained everything ok.
Many thanks for your help, Pat
Private db As New NFLSquaresPoolEntities
Protected Sub CreateTable()
Using db
Dim game = From g In db.Games, _
m In db.MemberInfoes, s In db.Squares, _
sd In db.SquareDetails _
Select g.gameId, g.homeTeam, g.visitingTeam, m.userName, s.squareId, s.x_pos, _
sd.x_value, s.y_pos, sd.y_value
Dim newTable As New Table()
newTable = SquaresTable
Dim tableString As New StringBuilder
Dim myString As String = ""
For Each square In db.Squares
Dim rowCnt As Integer = db.Squares.Count()
Dim newHeader As TableHeaderCell = New TableHeaderCell()
'Dim newCell As TableCell() = New TableCell(rowCnt) {}
Dim newCell As TableCell = New TableCell()
Dim newRow As New TableRow
Dim headerRow As New TableHeaderRow
For i = 0 To rowCnt
newCell = New TableCell
newHeader = New TableHeaderCell
newHeader.Scope = TableHeaderScope.Column
newHeader.Text = "?"
headerRow.Cells.Add(newHeader)
newCell.Text = "?"
Next
newTable.Controls.Add(headerRow)
newTable.Controls.Add(newRow)
Next
End Using
End Sub