Change color of GridView row

D

David C

I have a need to make a GridView row a different color (red) if a date
exists on the row. I assume I would do this in the OnDataBound event. I
know how to make a Cell(x) a different color but not a row. Thanks.

David
 
J

Jim in Arizona

David said:
I have a need to make a GridView row a different color (red) if a date
exists on the row. I assume I would do this in the OnDataBound event. I
know how to make a Cell(x) a different color but not a row. Thanks.

David

Here's some code I put together a while back as an additional example to
John's reply. Watch for wrap!

Sub doColor(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

Dim test As New BoundColumn()

If e.Row.RowType = DataControlRowType.DataRow Then
Dim i9, i10 As Integer

If Int32.TryParse(e.Row.Cells(9).Text, i9) AndAlso i9 >= 45
Then
e.Row.BackColor = Drawing.Color.LightYellow
e.Row.Cells(9).ForeColor = Drawing.Color.Red
e.Row.Cells(9).Font.Bold = True
End If

If Int32.TryParse(e.Row.Cells(9).Text, i9) AndAlso i9 < 0 Then
e.Row.BackColor = Drawing.Color.Yellow
e.Row.Cells(9).ForeColor = Drawing.Color.Red
e.Row.Cells(9).Font.Bold = True
End If

If Int32.TryParse(e.Row.Cells(10).Text, i10) AndAlso i10 >=
60 Then
e.Row.BackColor = Drawing.Color.LightYellow
e.Row.Cells(10).ForeColor = Drawing.Color.Red
e.Row.Cells(10).Font.Bold = True
End If

End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top