Data Grid Question

G

Guest

I'm trying to use a datagrid to display data and that has been easy - what
i'm trying to do is have a rows background color change to red if the first
databound column is 0 for the item. I have entered an onitemcreated sub
routine to handle the data item when its added to the grid but it hasn't
worked. This is my sub below:

Sub OnCreatedItem(ByVal sender As Object, ByVal e As
DataGridItemEventArgs)

If e.Item.Cells(0).Text = "0" Then
UnitLists.Items(e.Item.ID).BackColor =
System.Drawing.Color.ForestGreen
'e.Item.BackColor = System.Drawing.Color.ForestGreen
End If
End Sub

How do i code this so I can vary the background colors for the cells
depending on the data that it contains?

Thank you for your help,
Ryan
 
Y

Yunus Emre ALPÖZEN [MCAD.NET]

u should use datagrid's itemdatabound event instead of using oncreated item
..

because no data is set at item creation stage.. it should works at on
itemdatabound event

One more thing, don't use e.item.cells(0)

use a code like following;
Dim rw as DataRowView = e.item.DataItem
if rw!=null
rw(0).Equals("0")
or something similar this
 

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

Similar Threads


Top