Prev: GridView not populating, but not all the time, clearing cache
Next: Mail message attachement problem
From: DavidC on 22 Apr 2010 17:32 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 -- David
From: Alexey Smirnov on 25 Apr 2010 14:20
On Apr 22, 11:32 pm, DavidC <dlch...(a)lifetimeinc.com> wrote: > 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 > > -- > David http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.dotnet.framework.aspnet&tid=1ea4f98c-4325-4726-9a8b-5c5242f9383a&cat=&lang=&cr=&sloc=&p=1 |