DataList Highlighting

DataList Highlighting

am 29.01.2008 18:55:32 von 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

RE: DataList Highlighting

am 29.01.2008 19:42:01 von mily242

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
--
Milosz


"Joe" wrote:

> 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
>