Change ListView row background color

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