Get Row BackColor ItemDataBound

4 posts, 0 answers
  1. Jack
    Jack avatar
    128 posts
    Member since:
    May 2003

    Posted 12 Jun 2012 Link to this post

    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
  2. Eyup
    Admin
    Eyup avatar
    3006 posts

    Posted 13 Jun 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jack
    Jack avatar
    128 posts
    Member since:
    May 2003

    Posted 14 Jun 2012 Link to this post

    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
  5. Eyup
    Admin
    Eyup avatar
    3006 posts

    Posted 15 Jun 2012 Link to this post

    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.
Back to Top