This is a migrated thread and some comments may be shown as answers.

Get Row BackColor ItemDataBound

3 Answers 132 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 12 Jun 2012, 11:45 PM
Hi,

I need to change the row background color in ItemDataBound but can't find how to get that.

If oDataItem.DataItem("isAnswer") = True Then
              ' Change the background color of the whole row
 End If

Many thanks in advance

Jon

3 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 13 Jun 2012, 08:19 PM
Hi Jon,

Please try the following approach:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
        If TypeOf e.Item Is GridDataItem Then
            Dim dataItem As GridDataItem = TryCast(e.Item, GridDataItem)
            Dim freight As Double = Double.Parse(dataItem("Freight").Text)
            If freight > 60 Then
                dataItem.BackColor = System.Drawing.Color.LightPink
            End If
        End If
    End Sub

That should do the trick.

Kind regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Jon
Top achievements
Rank 1
answered on 14 Jun 2012, 07:34 AM
Hi Eyup,

For the list view the code in ItemDataBound I have is...

 If (TypeOf (e.Item) Is RadListViewDataItem) Then
            Dim oDataItem As RadListViewDataItem = CType(e.Item, RadListViewDataItem)

oDataItem does not have a property of BackColor, the nearest I can get is oDataItem.OwnerListView.BackColor = System.Drawing.Color.LightPink

But this doesn't work

Thanks in advance again.
Jon
0
Eyup
Telerik team
answered on 15 Jun 2012, 03:18 PM
Hello Jon,

I am afraid the desired functionality is not applicable programmatically with RadListView. However, I have attached a sample web site where I implemented the requested conditional modification on design-time. Please check it out and try to implement it on your own project.

Kind regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ListView
Asked by
Jon
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Jon
Top achievements
Rank 1
Share this question
or