[英]vb.net Conditional Formatting Gridview Cells
這是我的代碼,有條件地格式化特定的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
問題是小數沒有空值
因此,我希望單元格背景色為空時為白色(無編號),當前顯示為Firebrick,因為它將0歸類為無/空
關於如何實現這一目標的任何想法?
如果解析成功,Decimal.TryParse()應該具有返回值
嘗試:
'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.