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

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,737
Latest member
Georgeengab

Latest Threads

Top