0

我必须建立一个网页和语言表,即第 1 页:en it de 在一个最多可以有 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"">&nbsp;</td>"
        Else
            tableBody.Text += cell
        End If
    Next

    tableBody.Text += "</tr>"
Next

该表显示精美,但每一行都包含应该是最后一行的数据。如何修复它,以便每个 thisRow 在 rowArrayList 中都是唯一的?目前,每次将 thisRow 添加到 rowArrayList 时,都会覆盖每个 rowArrayList 索引,而不仅仅是添加的索引。

4

1 回答 1

1

为了快速修复,而不是这个:

Array.Clear(thisRow, 0, thisRow.Length)

做这个:

thisRow = New String(languageNum) {}

或这个:

ReDim thisRow(languageNum)

但是,我怀疑您可以更改一些简单的设计选择,这些选择会极大地改善此代码。

于 2013-10-10T21:12:37.223 回答