RadRotator ItemDataBound

3 posts, 0 answers
  1. Tracy Cole
    Tracy Cole avatar
    4 posts
    Member since:
    Feb 2009

    Posted 24 Jul 2009 Link to this post

    I'm using a Rotator to display a stock ticker using the StockQuoteService.    Everything works fine, but I want to be able to display an Up or Down image in the Rotator based on the change in the stock quote.   I'm following the example that I found online for the RadGrid, but can't get it to work with the Rotator.      Below is the code from the Grid example that does exactly what I need.   How can this be applied to a Rotator?

     Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs)
            If TypeOf e.Item Is GridDataItem Then
                Dim item As GridDataItem = CType(e.Item, GridDataItem)
                Dim cell As TableCell = item("Change")

                Dim directionImage As System.Web.UI.WebControls.Image = CType(cell.FindControl("DirectionImage"), System.Web.UI.WebControls.Image)
                Dim changeText As Label = CType(cell.FindControl("ChangeLabel"), Label)
                Dim change As [Decimal] = [Decimal].Parse(CType(e.Item.DataItem, DataRowView).Row("Change").ToString(), CultureInfo.InvariantCulture)
                If change > 0 Then
                    directionImage.ImageUrl = "Images/up.gif"
                    directionImage.AlternateText = "up"
                    changeText.Style("color") = "green"
                ElseIf change < 0 Then
                    directionImage.ImageUrl = "Images/down.gif"
                    directionImage.AlternateText = "down"
                    changeText.Style("color") = "red"
                    directionImage.Visible = False
                End If
            End If
        End Sub

  2. Tracy Cole
    Tracy Cole avatar
    4 posts
    Member since:
    Feb 2009

    Posted 28 Jul 2009 Link to this post

    Any ideas?    Basically what I'm trying to do is apply conditional formatting to the items in my Rotator.   If there is a better way to do this I'm open to suggestions.    Alternatively, if it's possible to modify the StockQuoteService to specify the image I can try that, but that approach seems to be fairly complex.    Thanks in advance for any help.
  3. Svetlina Anati
    Svetlina Anati avatar
    2795 posts

    Posted 29 Jul 2009 Link to this post

    Hello Tracy,

    As far as I understand you want to reference the controls in the item and to change their settings if needed and you are using an item template. If so, you can think of the rotator as a repeater - it is also an INaming Container and referencing the controls in the item should be done by using the FindControl method, e.g as shown below:

    Protected Sub RadRotator1_ItemDataBound(sender As Object, e As Telerik.Web.UI.RadRotatorEventArgs)  
        Dim directionImage As System.Web.UI.WebControls.Image = DirectCast(e.Item.FindControl("DirectionImage"), System.Web.UI.WebControls.Image)  
        Dim changeText As Label = DirectCast(e.Item.FindControl("ChangeLabel"), Label)  
        If condition Then 
            directionImage.ImageUrl = "Images/up.gif" 
            directionImage.AlternateText = "up" 
            changeText.Style("color") = "green" 
        End If 
    End Sub 

    On a side note, the forums are considered community resources and we do not guarantee a timely response here. If you want to ensure that you will get a faster response you should open support tickets.

    I hope that my explanation and the code snippet are helpful, lety me know how it goes.

    All the best,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top