[英]vb.net Conditional Formatting Gridview Cells
Here is my code that conditionally formats a specific Gridview cell (The value is a string that I convert to decimal) 这是我的代码,有条件地格式化特定的Gridview单元格(该值是我转换为十进制的字符串)
If e.Row.Cells(0).Text = "Total" Then
Dim c2 As Decimal
Decimal.TryParse(e.Row.Cells(7).Text, c2)
If c2 >= 0 And c2 <= 84 Then
e.Row.Cells(7).BackColor = Drawing.Color.Firebrick
e.Row.Cells(7).ForeColor = Drawing.Color.White
End If
If c2 >= 85 Then
e.Row.Cells(7).BackColor = Drawing.Color.LimeGreen
e.Row.Cells(7).ForeColor = Drawing.Color.Black
End If
End If
The problem is Decimals have no Null value 问题是小数没有空值
So I want the cell backcolor to be White when it's empty (as in no number), currently it shows as Firebrick because it classes 0 the same as nothing/null 因此,我希望单元格背景色为空时为白色(无编号),当前显示为Firebrick,因为它将0归类为无/空
Any ideas on how to achieve this? 关于如何实现这一目标的任何想法?
Decimal.TryParse() should have a return value if the parse was successfull 如果解析成功,Decimal.TryParse()应该具有返回值
try: 尝试:
'Code is not tested
Dim c2 As Decimal
If Not Decimal.TryParse(e.Row.Cells(7).Text, c2) Then
'No double value found
'Color as you wish
Else If c2 >= 0 And c2 <= 84 Then
e.Row.Cells(7).BackColor = Drawing.Color.Firebrick
e.Row.Cells(7).ForeColor = Drawing.Color.White
Else If c2 >= 85 Then
e.Row.Cells(7).BackColor = Drawing.Color.LimeGreen
e.Row.Cells(7).ForeColor = Drawing.Color.Black
End If
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.