Add charts to rad rotator

2 posts, 1 answers
  1. Tzach Kaufmann
    Tzach Kaufmann avatar
    95 posts
    Member since:
    Aug 2008

    Posted 22 Feb 2012 Link to this post

    Hi,

    I want to create a RadRotator with Charts (asp.net charting) inside.

    I tried a lot of ways to create it, but I couldn't see the charts inside.

    the first option:

    ascx:

     

    <telerik:RadRotator ID="RadRotator1" runat="server" RotatorType="Buttons"

     

     

    style="width:300px; height:300px; margin-left:10px; margin-top:30px;" ScrollDuration="500" FrameDuration="2000" ItemHeight="100" ScrollDirection="Up, Down"

     

     

    ItemWidth="100">

     

     

        <ItemTemplate>

     

     

        </ItemTemplate>
    </telerik:RadRotator >

    cs:

    Chart chart = new Chart():
    // adding chart styles, etc.
    RadRotator1.Items.Add(new RadRotatorItem(chart))


    second option:

     

     

    <telerik:RadRotator ID="RadRotator1" runat="server" RotatorType="Buttons"

     

     

     

     

     

    style="width:300px; height:300px; margin-left:10px; margin-top:30px;" ScrollDuration="500" FrameDuration="2000" ItemHeight="100" ScrollDirection="Up, Down"

     

     

     

     

     

    ItemWidth="100" OnItemCreated="RadRotator1_ItemCreated">

     

     

     

     

     

        <ItemTemplate>

     

     

     

     

     

     

     

     

            <asp:Chart ID="crtAlerts" runat="server" style="width:100px; Height:100px; margin-top:3px; margin-left:60px">

     

            </asp:Chart

     

        </ItemTemplate>

     

     

     

     

     

    </telerik:RadRotator>

    cs:

     

     

    protected void RadRotator1_ItemCreated(object sender, Telerik.Web.UI.RadRotatorEventArgs e)

     

    {

     

     

     

     

        Chart crtAlertsPerSZ = e.Item.FindControl("crtAlerts") as Chart;
        //adding styles to the chart, etc..
    }

    In this case, OnItemCreated is not fired.


    Is there a way to add asp.net chart control to rad rotator?

    Thanks.

     

  2. Answer
    Slav
    Admin
    Slav avatar
    1356 posts

    Posted 24 Feb 2012 Link to this post

    Hello Tzach,

    The first approach does not work because you should add the chart in the Controls collection of a newly created RadRotatorItem and then you need to insert this item in the Items collection of RadRotator, as shown below:
    Chart chart = new Chart();
    RadRotatorItem item = new RadRotatorItem();
    item.Controls.Add(chart);
    RadRotator1.Items.Add(item);

    In your second approach you have only defined the template of the RadRotator's items, but you have not databound the control. As a result it is not populated with items and the server-side event ItemCreated is not raised. For example, if you populate it as demonstrated in the following example, the charts will be displayed, because the RadRotator control will have items in its collection:
    RadRotator1.DataSource = new[] { "item", "item", "item" };
    RadRotator1.DataBind();

    Kind regards,
    Slav
    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
Back to Top