0

Web ページと言語のテーブル、つまりページ 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"">&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 に答える