Customize a DataGrid Row

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
 
T

Teemu Keiski

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.
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top