I'm trying to change the backcolor of a .Net GridView when a certain condition is met. This should be fairly straight forward, but the color change isn't happening. Checking the rendered HTML shows absolutely nothing different in the effected rows even though the text change on the link is happening as expected.
There is a default theme set for all gridviews and I haven't worked with that in the past. Is that preventing me from dynamically changing the color of a row or am I missing something else?
I'm using .Net 3.5 and have the following in my code behind:
Protected Sub gvPrevious_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles gvPrevious.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If currentCorrespondence.IsRetired Then //custom object, returning as expected
Dim link As LinkButton = DirectCast(e.Row.Controls(4).Controls(2), LinkButton)
link.Text = "Reinstate" //default is "retire" - GV renders this as expected
e.Row.BackColor = Drawing.Color.IndianRed //might as well not be here
End If
End If
End Sub
From the above code, when I go into the browser and view source, I would expect to see <tr style="background-color: #CD5C5C;">
for effected rows. Instead, I see <tr>
and <tr class="AlternateRowStyle">
(where appropriate). I see absolutely no effects from the BackColor property change.
I have also attempted to use e.Row.CssClass
with the same result.