Click to See Complete Forum and Search --> : Item databound


Funkymonkey
09-28-2005, 06:35 AM
I need a row to change colour if the value in a certain column in the database is true.

EG If the column "completed" in the database has a value of 'true' for a certain row then I'd like that row in the datagrid to be blue.

I have this:
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then

If e.Item.DataItem("Actioned") = "0" Then _
e.Item.BackColor = System.Drawing.Color.FromName("#ff6")

Which works but I need to add to it so that the value of "completed" is looked up in the database rather than the datagrid like above.

Thanks

alon
09-29-2005, 10:27 AM
Add a label with the primary key of your table to the datagrid (make it invisible), find the row according to the label's value, and set the datagrid's row color accordingly.

Funkymonkey
03-09-2006, 06:32 AM
If e.Row.RowType = DataControlRowType.DataRow Then
'Determine the value of the Actioned field and colour accordingly
Dim Actioned As String = (DataBinder.Eval(e.Row.DataItem, "Actioned"))
If Actioned = "False" Then
' Color the background of the row yellow
e.Row.BackColor = System.Drawing.Color.FromName("#D7E3F4")
ElseIf Actioned = "True" Then
' Color the background of the row yellow
e.Row.BackColor = System.Drawing.Color.FromName("#EFF3FB")
End If
End If