Does having a theme for a GridView prevent changes to a row's backcolor property on RowDataBound
I'm trying to change the backcolor
of a .Net GridView
when a certain condition is met. This should be fairly straightforward, but the color change isn't happening. Checking the rendered HTML shows absolutely nothing different in the affected 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 the affected rows. Instead, I see <tr>
and <tr class="AlternateRowStyle">
(where appropriate). I see absolutely no effect from t开发者_运维百科he BackColor
property change.
I have also attempted to use e.Row.CssClass
with the same result.
try something like this:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Select Case e.Row.RowState
Case DataControlRowState.Normal
CType(e.Row, GridViewRow).Style.Add("background", "#CD5C5C")
End Select
End Sub
精彩评论