Rebind RadRotator

2 posts, 0 answers
  1. Prateek
    Prateek avatar
    2 posts
    Member since:
    Sep 2012

    Posted 18 Apr 2013 Link to this post

    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>
  2. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 23 Apr 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top