DataList Highlighting

  • Thread starter Thread starter Joe
  • Start date Start date
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
 
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
 
Back
Top