ASP VB根据另一列中的值更改GridView中列的单元格颜色

时间:2013-04-04 11:08:35

标签: sql visual-studio-2010 gridview backcolor

我创建了一个包含多列的gridview。我想根据差异列中的值更改“教师评估”列的背景列。根据我下面的当前代码,颜色的变化是有效的,但它为整行着色,我只想将它应用到教师评估专栏。

我会截图,但我还没有代表,所以我会尝试用文字显示:

Target    Teacher Assessment    Difference    (TA column colour)
C+        B-                    1             Green
C+        C-                    -2            Red
C+        C+                    0             Yellow

以下是我正在使用的代码,用于触发从网络上的某些代码修改的背景颜色更改,以回答类似问题:

Protected Sub gdViewAllopen_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.DataRow Then
        Dim number = DirectCast(e.Row.DataItem, DataRowView)("Difference").ToString()
        Select Case number
            Case 0
                e.Row.BackColor = System.Drawing.Color.Yellow
            Case Is > 0
                e.Row.BackColor = System.Drawing.Color.Green
            Case Is < 0
                e.Row.BackColor = System.Drawing.Color.Red
        End Select
    End If
End Sub

宣布它!这么容易!!好吧,这是为了别人的利益。只需在Cells(n)之后添加Row

e.Row.Cells(2).BackColor = System.Drawing.Color.Yellow

1 个答案:

答案 0 :(得分:1)

宣布它!这么容易!!好吧,这是为了别人的利益。只需在Cells(n)之后添加Row

e.Row.Cells(2).BackColor = System.Drawing.Color.Yellow