Change ListView row background color

D

DavidC

I have an asp.net listView that I want to change the background color based
on a condition. I have started to do something in the ItemDataBound event
but cannot find out what method or ??? to use to assign a background color.
I have done this in a GridView but this is the first I have tried in
ListView. Below is my code if someone can help. Thanks.

Protected Sub lvPTODetails_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.ListViewItemEventArgs) Handles
lvPTODetails.ItemDataBound
Dim dataItem As ListViewDataItem = CType(e.Item, ListViewDataItem)
Dim rowView As DataRowView = CType(dataItem.DataItem, DataRowView)
' Retrieve the Vendor value for the current item.
Dim dblAvailable As Double =
Convert.ToDouble(rowView("UnitsAvailable"))
If dblAvailable <> 0 Then
'do something here to change background color
End If
End Sub
 
G

Guest

I have an asp.net listView that I want to change the background color based
on a condition.  I have started to do something in the ItemDataBound event
but cannot find out what method or ??? to use to assign a background color.  
I have done this in a GridView but this is the first I have tried in
ListView.  Below is my code if someone can help.  Thanks.

    Protected Sub lvPTODetails_ItemDataBound(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.ListViewItemEventArgs) Handles
lvPTODetails.ItemDataBound
        Dim dataItem As ListViewDataItem = CType(e.Item, ListViewDataItem)
        Dim rowView As DataRowView = CType(dataItem.DataItem, DataRowView)
        ' Retrieve the Vendor value for the current item.
        Dim dblAvailable As Double =
Convert.ToDouble(rowView("UnitsAvailable"))
        If dblAvailable <> 0 Then
            'do something here to change background color
        End If
    End Sub

http://www.microsoft.com/communitie...26-9a8b-5c5242f9383a&cat=&lang=&cr=&sloc=&p=1
 

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,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top