I have a databound grideview where I want to color-code the cells in my aspx.vb back end, based on criteria... I started with:
If IsDBNull(DataBinder.Eval(e.Row.DataItem, "SwitchPort1")) = True Then
e.Row.Cells(3).ForeColor = Drawing.Color.Black
Else
e.Row.Cells(3).BackColor = Drawing.Color.Green
End If
***
This worked, so then I decided to add some ElseIf statements to it, and have it look at the difference between NullOrEmpty, but cannot get the syntax right. There are several examples, but for whatever reason, I am not getting past the first "If", nothing else is being evaluated. I test the database values to force a change in the cell color, and cannot make the cells do anything but White with Black Text (if db is null) OR Green Background (Else). Can anyone help me figure out what I am doing wrong? "Guest" is a specific value, for which I want to search, and if present - a specific color.
If (e.Row.RowType <> DataControlRowType.DataRow) Then
Exit Sub
End If
If IsDBNull(DataBinder.Eval(e.Row.DataItem, "SwitchPort1")) = True Then
e.Row.Cells(3).ForeColor = Drawing.Color.Black
ElseIf Len(DataBinder.Eval(e.Row.DataItem, "SwitchPort1")) = 0 Then
e.Row.Cells(3).BackColor = Drawing.Color.Black
ElseIf DataBinder.Eval(e.Row.DataItem, "SwitchPort1").ToString = "" Then
e.Row.Cells(3).BackColor = Drawing.Color.Blue
ElseIf DataBinder.Eval(e.Row.DataItem, "SwitchPort1").ToString = "Guest" Then
e.Row.Cells(3).BackColor = Drawing.Color.Yellow
Else
e.Row.Cells(3).BackColor = Drawing.Color.Green
End If
What I have tried:
I have tried looking at various different sites to find references, but nothing is really explaining things in a way I understand. I have tried testing numerous lines of changes, Dim String statements, and testing the String, but I am just hitting a brick wall.