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

Rebind RadRotator

1 Answer 58 Views
Rotator
This is a migrated thread and some comments may be shown as answers.
Prateek
Top achievements
Rank 1
Prateek asked on 18 Apr 2013, 09:20 PM
Hello, 

I am using a RadRotator in Sitefinity. I have bound images to it on PageLoad. It works fine. Now I want to rebind the control on filtering by category. When I click the category the DataSource is new, but it doesn't do anything to the images. It still shows the original set.

This is how I bind:

VideosCarousel.DataSource = GetVideos("All");
VideosCarousel.DataBind();

And to rebind I do this:

VideosCarousel.DataSource = null;
VideosCarousel.DataBind();             
VideosCarousel.DataSource = GetVideos("Business");
VideosCarousel.DataBind();

The categories are "a" links. Like this:

<li><a id="all" onclick="GetAllVideos(this)">All</a></li>
 <li><a id="buss" onclick="GetFilteredVideos(this)">Business</a></li>
<li><a id="cnh" onclick="GetFilteredVideos(this)">Community&Health</a></li>
<li><a id="tech" onclick="GetFilteredVideos(this)">Technology</a></li>

1 Answer, 1 is accepted

Sort by
0
Slav
Telerik team
answered on 23 Apr 2013, 02:36 PM
Hello Prateek,

It is not required to set a null datasource for the RadRotator in order to rebind it. All you need to do is perform a full or partial postback (in this case you should ensure that the rotator is updated by the AJAX request), set a different datasource and invoke the DataBind method of the rotator. You can check this in the code sample below:

Page
<telerik:RadRotator ID="RadRotator1" runat="server" FrameDuration="3000" RotatorType="Buttons"
    Height="113px" ItemHeight="113px" Width="190px" ItemWidth="150px"
    Skin="Default">
    <ItemTemplate>
        <img src="<%# ResolveUrl("images/" + Container.DataItem) %>" alt="" />
    </ItemTemplate>
</telerik:RadRotator>
<asp:Button Text="Rebind rotator" runat="server" />

Code-behind
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        RadRotator1.DataSource = new[] { "barcelona.jpg", "london.jpg", "paris.jpg" };
        RadRotator1.DataBind();
    }
    else
    {
        RadRotator1.DataSource = new[] { "dubrovnik.jpg", "luxembourg.jpg", "piza.jpg" };
        RadRotator1.DataBind();
    }
}

All the best,
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.
Tags
Rotator
Asked by
Prateek
Top achievements
Rank 1
Answers by
Slav
Telerik team
Share this question
or