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

How do I add items to a rotator programmatically?

1 Answer 149 Views
Rotator
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 24 May 2012, 12:41 AM
Can someone tell me why this code doesn't work? Checked the demos and documentation but didn't find an answer and the forum related to this topic are very old.

<telerik:RadRotator ID="rotator1" runat="server" Width="800px" Height="150px" SlideShowAnimation-Type="Fade" SlideShowAnimation-Duration="500" ItemHeight="63" ItemWidth="125" RotatorType="Buttons" OnClientItemShown="OnClientItemShown"></telerik:RadRotator>
var item = new Telerik.Web.UI.RadRotatorItem();
item.Controls.Add(new LiteralControl("<div>1</div>"));
rotator1.Items.Add(item);

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 May 2012, 06:44 AM
Hi Jeff,

As far as I know, a control can added only to an ItemTemplate. Since you are adding a LiteralControl dynamically, you must define a custom class that implements the ITemplate interface. Here is the sample code.

ASPX:
<telerik:RadRotator ID="RadRotator1" runat="server" Width="800px" Height="150px" SlideShowAnimation-Type="Fade" SlideShowAnimation-Duration="500" ItemHeight="63" ItemWidth="125" RotatorType="Buttons" DataSourceID="SqlDataSource1">
</telerik:RadRotator>

C#:
public partial class exercise_rotator : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        RadRotator1.ItemTemplate = new MyItemTemplate();
        base.OnInit(e);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
    }
}
internal class MyItemTemplate : ITemplate
{
    public void InstantiateIn(Control container)
    {
        LiteralControl ltl = new LiteralControl("<div>1</div>");
        container.Controls.Add(ltl);
    }
}

Thanks,
Princy.
Tags
Rotator
Asked by
Jeff
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or