在vb.net(aspx)循环中设置当前行的背景颜色

时间:2018-04-02 08:41:17

标签: asp.net vb.net loops

我正在尝试遍历GridView1上的所有行,并在处理行时更改行的backgournd颜色。

循环完美无缺,但由于某种原因,设置Back Color的代码行没有得到尊重。

nextRow.BackColor = System.Drawing.Color.RoyalBlue

这是完整的循环。

For i As Integer = 0 To GridView1.Rows.Count - 1

    Dim counter As Integer = GridView1.SelectedIndex + 1
    Dim nextRow As GridViewRow

    nextRow = GridView1.Rows(0)
    If counter = GridView1.Rows.Count Then
        nextRow = GridView1.Rows(0)

    Else

        'formatting
        nextRow.BackColor = System.Drawing.Color.RoyalBlue

        nextRow = GridView1.Rows(counter)
        CompileHTML(GridView1.Rows(i))
        ExportHTML(GridView1.Rows(i))

    End If
Next

1 个答案:

答案 0 :(得分:0)

您正在将nextRow的值设置为if语句正上方的第一行,因此当设置backcolor时,nextRow始终为GridView1.Rows(0)。

For Each row As GridViewRow In GridView1.Rows
    row.BackColor = System.Drawing.Color.RoyalBlue
Next