Sql ASP VB根据另一列中的值更改GridView中列的单元格颜色
我已经创建了一个包含多个列的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-
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