我必须建立一个网页和语言表,即第1页:在一个最多可能有14种语言的模式中。页面内容保存在数据库中。因此,要构建表格,请执行以下操作:
Dim rowArrayList As New ArrayList
Dim thisRow(languageNum) As String 'languageNum equates to number of columns -1
数据库访问:
'# Create row array of cell arrays
If pageName <> lastPageName Then
lastPageName = pageName
If j >= languageNum Then
rowArrayList.Add(thisRow)
Array.Clear(thisRow, 0, thisRow.Length)
j = 0
End If
thisRow(0) = "<td class=""pageName"">" & pageName & "</td>"
End If
'# Iterate each cell in the row
For i As Integer = 1 To languageNum - 1
If thisRow(i) = "" Then
If transReady = False And active = False Then
thisRow(i) = "<td class=""trans""><a href=""content/page-text.aspx?pageID=" & SQLReader("DAEPageContentControlID").ToString() & "&lang=" & langISO & """>" & langISO & "</a></td>"
ElseIf transReady = True And active = False Then
thisRow(i) = "<td class=""notActive""><a href=""content/page-text.aspx?pageID=" & SQLReader("DAEPageContentControlID").ToString() & "&lang=" & langISO & """>" & langISO & "</a></td>"
ElseIf transReady = True And active = True And i = thisLangID Then
thisRow(i) = "<td class=""active""><a href=""content/page-text.aspx?pageID=" & SQLReader("DAEPageContentControlID").ToString() & "&lang=" & langISO & """>" & langISO & "</a></td>"
End If
End If
j = j + 1
Next
构建表:
'# Build output table
For Each row As String() In rowArrayList
tableBody.Text += "<tr>"
For Each cell As String In row
If cell = "" Then
tableBody.Text += "<td class=""notTrans""> </td>"
Else
tableBody.Text += cell
End If
Next
tableBody.Text += "</tr>"
Next
表格显示精美但每行包含应该是最后一行的数据。怎么能修复它所以每个thisRow在rowArrayList中是唯一的?目前,每次将thisRow添加到rowArrayList时,每个rowArrayList索引都会被覆盖,而不仅仅是被添加的索引。
答案 0 :(得分:1)
对于快速修复,而不是:
Array.Clear(thisRow, 0, thisRow.Length)
这样做:
thisRow = New String(languageNum) {}
或者这个:
ReDim thisRow(languageNum)
但是,我怀疑你可以改变一些简单的设计选择,这会大大改变这段代码。