DataList Highlighting

J

Joe

Hi,

I am attempting to highlight rows in my datalist based on a
value in the database. My event handler is shown below:

Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DataListItemEventArgs) Handles
DataList1.ItemDataBound


Dim Discontinued As Boolean = (CType(e.Item.DataItem,
DataRowView)).Row.ItemArray(2).ToString()

If Discontinued = True Then
DataList1.ItemStyle.BackColor = Drawing.Color.Yellow
Else
DataList1.ItemStyle.BackColor = Drawing.Color.White
End If
End Sub

It compiles and runs fine, and the Discontinued value is the
correct value when I run it through the debugger - but the BackColor
does not change.

Can anyone tell me what I am doing wrong in setting the
BackColor?

Thanks,
J
 
M

Milosz Skalecki [MCAD]

Howdy,

It's not gonna work because you're changing ItemStyle property, which is
used as base style for all rows, including alternating ones. You have to
amend the code to:
If Discontinued = True Then
e.Item.BackColor = Drawing.Color.Yellow
Else
e.Item.BackColor = Drawing.Color.White
End If

Hope it helps
 

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