Help with setting row backcolor

G

Guest

Hi,
I am trying to set a row backcolor based on the value of a cell in my
datagrid but it's not working

This is what I have

Private Sub grdProcessingTitles_ItemDataBound(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
grdPro.ItemDataBound

If e.Item.Cells(4).Text = "Pending" Then

e.Item.BackColor = Color.Lime

End If

End Sub

Any ideas?

Thanks
 
G

Guest

Just spent hours on this one myself, here is what I found in case you still
need a solution, use ItemDataBound (find your controls):

Public Sub gdconcerndetail_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
gdconcerndetail.ItemDataBound

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim careq As Boolean =
CType(e.Item.Cells(3).FindControl("ckcareq"), CheckBox).Checked
Dim cadate As Date =
CType(e.Item.Cells(4).FindControl("lblcadatereq"), Label).Text
Dim todaydate1 As Date = Date.Now()
'Response.Write("ItemDataBound findcontrol ckcareq = " &
CType(e.Item.Cells(3).FindControl("ckcareq"), CheckBox).Checked & "<br>")
'Response.Write("ItemDataBound findcontrol lblcadatereq = " &
CType(e.Item.Cells(4).FindControl("lblcadatereq"), Label).Text & "<br>")

If careq = True Then
If todaydate1 > cadate Then
'make item red because it is past the due date
e.Item.BackColor = Color.Red
End If

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

Top