Customize a DataGrid Row

  • Thread starter Thread starter James Lennon
  • Start date Start date
J

James Lennon

How can I customize a DataGrid row based on the row
properties. For istance if a column is 0 make the row
bold or red. I have only been able to format a datagrid
based on columns.

James
 
Hi,

say in ItemDataBound event handler for the grid you could change the
properties of the DataGridItem (current item being databound). The item is
given in the second event argument of type DataGridItemEventArgs for the
event handler method.

Say:

Public Sub MyGrid_ItemDataBound(sender As Object,e As DataGridItemEventArgs)
Handles MyGrid.ItemDataBound
If e.Item.ItemType==ListItemType.Item OrElse
e.Item.ItemType==ListItemType.AlternatingItem Then
If [somethingevaluatedhere] Then
e.Item.BackColor=Color.Red
End If
End If
End Sub

The DataGridItem represents the current row (item) as a whole and changing
its properties as I changed BackColor in the example (when condition
matches), you can customize it as you like.
 
Back
Top