Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql ASP VB根据另一列中的值更改GridView中列的单元格颜色_Sql_Visual Studio 2010_Gridview_Backcolor - Fatal编程技术网

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

Sql ASP VB根据另一列中的值更改GridView中列的单元格颜色,sql,visual-studio-2010,gridview,backcolor,Sql,Visual Studio 2010,Gridview,Backcolor,我已经创建了一个包含多个列的gridview。我想根据差异栏中的值更改教师评估栏的背景栏。根据我目前的代码,下面的颜色变化是有效的,但它给整行着色,我只想把它应用到教师评估栏 我会截图,但我还没有代表,所以我会尝试用文字显示: Target Teacher Assessment Difference (TA column colour) C+ B- 1 Green C+ C-

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

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

Target    Teacher Assessment    Difference    (TA column colour)
C+        B-                    1             Green
C+        C-                    -2            Red
C+        C+                    0             Yellow
以下是我目前使用的代码,用于触发背景颜色的更改,该更改是根据web上对类似问题的回答中发现的一些代码修改的:

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
受保护的子gdViewAllopen\u行数据绑定(ByVal发送方作为对象,ByVal e作为GridViewRowEventArgs)
如果e.Row.RowType=DataControlRowType.DataRow,则
Dim编号=DirectCast(如Row.DataItem、DataRowView)(“差异”).ToString()
选择案例编号
案例0
e、 Row.BackColor=System.Drawing.Color.Yellow
大小写>0
e、 Row.BackColor=System.Drawing.Color.Green
病例<0
e、 Row.BackColor=System.Drawing.Color.Red
结束选择
如果结束
端接头


成功了!也很简单!!啊,好吧,这是为了其他人的利益。只需在
行之后添加
单元格(n)


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

使用它!也很简单!!啊,好吧,这是为了其他人的利益。只需在
行之后添加
单元格(n)


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

Matt,为什么要使用ToString()生成设置变量“number”,然后将其作为整数进行比较?另外,上面的第一行末尾不应该有这样的内容:Handles gvManageStore.RowDataBound