row color & Datagrid

N

n

I have a datagrid with many records, and i want to give specific color to
rows (i have a boundcolum with value from 1 to 4 and i want green row when
the value is 1, red row when the value is 2 end so on...

Any idea ?
 
C

Cristian Suazo

add this to the ItemDataBound event of the datagrid:

protected Sub dgTest_ItemBound(ByVal sender As Object, ByVal e As
DataGridItemEventArgs) Handles dgTest.ItemDataBound
If Not IsNothing(e.Item.DataItem) Then
Select Case e.Item.DataItem("TheColumn")
Case 1
e.Item.BackColor = Color.Aqua
Case 2
e.Item.BackColor = Color.Azure
End Select
End If
End Sub


Cheers
Cristian
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top