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

RadRotator ItemDataBound

2 Answers 178 Views
Rotator
This is a migrated thread and some comments may be shown as answers.
Tracy Cole
Top achievements
Rank 1
Tracy Cole asked on 24 Jul 2009, 03:28 PM
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"
            Else
                directionImage.Visible = False
            End If
        End If
    End Sub

2 Answers, 1 is accepted

Sort by
0
Tracy Cole
Top achievements
Rank 1
answered on 28 Jul 2009, 04:36 PM
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.
0
Svetlina Anati
Telerik team
answered on 29 Jul 2009, 12:27 PM
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,
Svetlina
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.
Tags
Rotator
Asked by
Tracy Cole
Top achievements
Rank 1
Answers by
Tracy Cole
Top achievements
Rank 1
Svetlina Anati
Telerik team
Share this question
or