我正在尝试遍历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
答案 0 :(得分:0)
您正在将nextRow的值设置为if语句正上方的第一行,因此当设置backcolor时,nextRow始终为GridView1.Rows(0)。
For Each row As GridViewRow In GridView1.Rows
row.BackColor = System.Drawing.Color.RoyalBlue
Next