Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to format table row

Status
Not open for further replies.

chedjou1971

Programmer
May 21, 2008
3
0
0
CA
What I'm trying to do is a table with a header row and multiple column, but each row should have a title formatted like the header row.
When I'm adding the <th>, my output give me an empty colunm before each column.
What can I do?

Here is a sample of the code used to build the table

Dim varHeader = (From item In m_vsViewModel.RecalcDetails Select item.PayCategoryCode).Distinct()

For i As Integer = 0 To varHeader.Count + 1
Dim c As New TableHeaderCell()
Dim l As New Literal()
If i = 0 Then
l.Text = ""
'l.Visible = False
'ElseIf i = 1 Then
' l.Text = ""
ElseIf i = varHeader.Count + 1 Then
l.Text = String.Format(MyBase.GetCommonResource("litTotal", "Text") & " ($)")
Else
l.Text = varHeader.ToArray(i - 1) & " ($)"
End If
c.Controls.Add(l)
HeaderTableHeaderRow.Cells.Add(c)
Next

' Create more rows for the table.
' Total number of rows
Dim rowNum As Integer
'Amount total for each row
Dim totRow2 As Integer = 0
Dim totRow3 As Integer = 0
Dim totRow4 As Integer = 0
Dim totRow5 As Integer = 0
Dim totRow6 As Integer = 0
Dim totRow7 As Integer = 0
Dim totRow9 As Integer = 0
Dim totRow10 As Integer = 0
Dim totRow11 As Integer = 0
Dim totRow12 As Integer = 0

For rowNum = 0 To 11
Dim tempRow As New TableRow()
Dim cellNum As Integer
For cellNum = 0 To varHeader.Count + 1
Dim tempCell As New TableCell()
Dim s As New LiteralControl()
'Amount total for each colunm
Dim intCol1 As Integer = 0
Dim intCol2 As Integer = 0
Dim intCol3 As Integer = 0

If cellNum = 0 Then

If SessionData.SidebarCategory <> 23 Then
Select Case rowNum
Case 8
s.Text = String.Format(MyBase.GetPageResource("lblCA", "Text"))
Case 9
s.Text = String.Format(MyBase.GetPageResource("lblAIP", "Text"))
End Select
Else
Select Case rowNum
Case 8
s.Text = String.Format(MyBase.GetPageResource("lblCA", "Text"))
s.Visible = False
Case 9
s.Text = String.Format(MyBase.GetPageResource("lblAIP", "Text"))
s.Visible = False
End Select
End If
Select Case rowNum
Case 0
s.Text = String.Format("<colspan=10 HorizontalAlign=left>" & MyBase.GetPageResource("lblPaidToDate", "Text"))
Case 1
s.Text = String.Format(objdata.Line1)
Case 2
s.Text = String.Format(objdata.Line2)
Case 3
s.Text = String.Format(objdata.Line3)
Case 4
s.Text = String.Format(objdata.Line10)
Case 5
s.Text = String.Format(objdata.Line4)
Case 6
s.Text = String.Format(MyBase.GetPageResource("lblTotalPaid", "Text"))
Case 7
s.Text = String.Format("<colspan=10 HorizontalAlign=left>" & MyBase.GetPageResource("lblSchedPay", "Text"))
Case 10
s.Text = String.Format(MyBase.GetPageResource("lblTotalSched", "Text"))
Case 11
s.Text = String.Format(MyBase.GetPageResource("lblTotalSched", "Text"))
End Select
tempCell.Controls.Add(s)
tempCell.Text = "<th>" & tempCell.Text & "</th>"
tempRow.Cells.Add(tempCell)

HeaderTable.Rows.Add(tempRow)

ElseIf cellNum > 0 And cellNum < varHeader.Count + 1 Then

For intCount As Integer = 0 To objdata.RecalcDetails.Count - 1
If SessionData.SidebarCategory <> 23 Then
Select Case rowNum
Case 8
If objdata.RecalcDetails.Item(intCount).LineIdFlag = False And objdata.RecalcDetails.Item(intCount).LineId = 5 And
objdata.RecalcDetails.Item(intCount).PayCategoryId = cellNum Then
tempCell.Text = String.Format(objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt.ToString)
totRow9 = totRow9 + objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt
End If
Case 9
If objdata.RecalcDetails.Item(intCount).LineId = 6 And objdata.RecalcDetails.Item(intCount).PayCategoryId = cellNum Then
tempCell.Text = String.Format(objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt.ToString)
totRow10 = totRow10 + objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt
End If
End Select
Else
Select Case rowNum
Case 8
tempCell.Text = String.Format(objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt.ToString)
tempCell.Visible = False
Case 9
tempCell.Text = String.Format(objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt.ToString)
tempCell.Visible = False
End Select
End If
Select Case rowNum
Case 0
tempCell.Visible = False
Case 1
If objdata.RecalcDetails.Item(intCount).LineId = 1 And objdata.RecalcDetails.Item(intCount).PayCategoryId = cellNum Then
tempCell.Text = String.Format(objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt.ToString)
totRow2 = totRow2 + objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt
End If
Case 2
If objdata.RecalcDetails.Item(intCount).LineId = 2 And objdata.RecalcDetails.Item(intCount).PayCategoryId = cellNum Then
tempCell.Text = String.Format(objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt.ToString)
totRow3 = totRow3 + objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt
End If
Case 3
If objdata.RecalcDetails.Item(intCount).LineId = 3 And objdata.RecalcDetails.Item(intCount).PayCategoryId = cellNum Then
tempCell.Text = String.Format(objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt.ToString)
totRow4 = totRow4 + objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt
End If
Case 4
If objdata.RecalcDetails.Item(intCount).LineId = 10 And objdata.RecalcDetails.Item(intCount).PayCategoryId = cellNum Then
tempCell.Text = String.Format(objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt.ToString)
totRow5 = totRow5 + objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt
End If
Case 5
If objdata.RecalcDetails.Item(intCount).LineId = 4 And objdata.RecalcDetails.Item(intCount).PayCategoryId = cellNum Then
tempCell.Text = String.Format(objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt.ToString)
totRow6 = totRow6 + objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt
End If
Case 6
If objdata.RecalcDetails.Item(intCount).PayCategoryId = cellNum And (objdata.RecalcDetails.Item(intCount).LineId <> 5 And
objdata.RecalcDetails.Item(intCount).LineId <> 6 And objdata.RecalcDetails.Item(intCount).LineId <> 7 And
objdata.RecalcDetails.Item(intCount).LineId <> 8 And objdata.RecalcDetails.Item(intCount).LineId <> 9) Then
intCol1 = intCol1 + objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt
tempCell.Text = String.Format(CsgcConvert.ParseString(intCol1))
totRow7 = totRow7 + intCol1
End If
Case 7
tempCell.Visible = False
Case 10
If objdata.RecalcDetails.Item(intCount).LineId = 7 And objdata.RecalcDetails.Item(intCount).PayCategoryId = cellNum Then
tempCell.Text = String.Format(objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt.ToString)
totRow11 = totRow11 + objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt
End If End Select
tempCell.HorizontalAlign = HorizontalAlign.Right
tempRow.Cells.Add(tempCell)

If rowNum = 11 Then
If objdata.RecalcDetails.Item(intCount).PayCategoryId = cellNum And (objdata.RecalcDetails.Item(intCount).LineId <> 5 And
objdata.RecalcDetails.Item(intCount).LineId <> 6 And objdata.RecalcDetails.Item(intCount).LineId <> 8 And
objdata.RecalcDetails.Item(intCount).LineId <> 9) Then
If objdata.RecalcDetails.Item(intCount).LineId = 7 Then
intCol3 = intCol3 + objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt
totRow12 = totRow12 + objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt
Else
intCol3 = intCol3 - objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt
totRow12 = totRow12 - objdata.RecalcDetails.Item(intCount).RecalcDetailAmnt
End If
tempCell.Text = String.Format(CsgcConvert.ParseString(If(intCol3 < 0, -intCol1, intCol3)))
End If
tempRow.Cells.Add(tempCell)
End If

Next

ElseIf cellNum = varHeader.Count + 1 Then

If SessionData.SidebarCategory <> 23 Then
Select Case rowNum
Case 8
If objdata.RecalcDetails.Item(cellNum).LineIdFlag = False Then
tempCell.Visible = True
tempCell.Text = String.Format(CsgcConvert.ParseString(totRow9))
End If
Case 9
If objdata.RecalcDetails.Item(cellNum).LineIdFlag = False Then
tempCell.Visible = True
tempCell.Text = String.Format(CsgcConvert.ParseString(totRow10))
End If
End Select
Else
Select Case rowNum
Case 8
tempCell.Text = String.Format(CsgcConvert.ParseString(totRow9))
tempCell.Visible = False
Case 9
tempCell.Text = String.Format(CsgcConvert.ParseString(totRow10))
tempCell.Visible = False
End Select
End If

Select Case rowNum
Case 0
tempCell.Visible = False
Case 1
tempCell.Text = String.Format(CsgcConvert.ParseString(totRow2))
Case 2
tempCell.Text = String.Format(CsgcConvert.ParseString(totRow3))
Case 3
tempCell.Text = String.Format(CsgcConvert.ParseString(totRow4))
Case 4
tempCell.Text = String.Format(CsgcConvert.ParseString(totRow5))
Case 5
tempCell.Text = String.Format(CsgcConvert.ParseString(totRow6))
Case 6
tempCell.Text = String.Format(CsgcConvert.ParseString(totRow2 + totRow3 + totRow4 + totRow5 + totRow6))
Case 7
tempCell.Visible = False
Case 10
tempCell.Text = String.Format(CsgcConvert.ParseString(totRow11)) End Select
tempCell.HorizontalAlign = HorizontalAlign.Right
tempRow.Cells.Add(tempCell)

If rowNum = 11 Then
tempCell.Text = "<th>" & String.Format(CsgcConvert.ParseString(If(totRow12 < 0, -totRow12, totRow12))) & "</th>"
tempRow.Cells.Add(tempCell)
End If

End If

Next
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top