Loading Images/FlashBanners in Rotator from DataBase

5 posts, 0 answers
  1. Telerik Admin
    Telerik Admin avatar
    1679 posts
    Member since:
    Oct 2004

    Posted 15 Aug 2007 Link to this post


    RadControls version

    RadRotator v.2.62+

    .NET version

    ASP.NET 2.0

    Visual Studio version


    programming language


    browser support

    all browsers supported by RadControls

    The most common use of the a rotator control is to rotate images and flash banners on a webpage. These images and Flash banners are sometimes loaded from a database. The following project demonstrates the use of r.a.d.rotator to display either images, flash banners, or a combination of the two and assumes you use virtual paths from your database table pointing to the excact locations of the image files in your app.( You will find an example attached at the bottom of this description.


    1. Set your images and/or flash banners in the right directory of your web application.
    2. Set up your database and Images/Flash Banners table.
      Lets say you have an 'Images' table in your database as in our case, you could have an ImageAddress and Extension column.
    3. Create asp panels within the rotetor frametemplate to hold :

      a) the flash banner embed object and
      b)the images from the database

      and databind to the ImageAddress field (note that the ItemDataBound event will be used).
      In this example, we demonstrate how to alternate between images and flash banners
      If you just need images only or just flash banners, you can just use one panel for either the images or the flash banners.
      So we have the following in our aspx:
      <radr:radrotator id="rotator1" runat="server" datasourceid="SqlDataSource1" frametimeout="2050" 
          height="60px" transitioneffect="gradientwipe" width="468px" onitemdatabound="rotator1_ItemDataBound">  
              <div style="text-align: center">  
                  <asp:panel id="flashPanel" runat="server" visible="false">  
                      <object id="coolspot" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash4/cabs/swflash.cab#version=4,0,0,0" 
                          height="60" width="800">  
                          <param name="movie" value='<%# Page.ResolveUrl((string)DataBinder.Eval(Container.DataItem, "ImageAddress")) %>'>  
                          <param name="quality" value="high">  
                          <param name="bgcolor" value="#000000">  
                          <embed bgcolor="#000000" height="60" name="coolspot" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" 
                              quality="high" src='<%# Page.ResolveUrl((string)DataBinder.Eval(Container.DataItem, "ImageAddress")) %>' 
                              type="application/x-shockwave-flash" width="800">  
                  <asp:panel runat="server" id="imagePanel" visible="false">  
                      <img id="Images" runat="server" alt="" class="RotatorImage" src='<%# DataBinder.Eval(Container.DataItem, "ImageAddress") %>' /> 

    4. Hook to the ItemDataBound event and add the following in the codebehind to check the file extension for whether to display an Image or a Flash Banner. (This can be easily done to display only one or the other):
    5. For alternating images/flashbanners:

      protected void rotator1_ItemDataBound(object sender, Telerik.WebControls.RadRotatorItemEventArgs e)  
          string extension = (string)DataBinder.Eval(e.Item.DataItem, "Extension");  
          if (extension == ".swf")  
              Panel flashPanel = (Panel)e.Item.FindControl("flashPanel");  
              flashPanel.Visible = true;  
              Panel imagePanel = (Panel)e.Item.FindControl("imagePanel");  
              imagePanel.Visible = true;  


      Protected Sub rotator1_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.WebControls.RadRotatorItemEventArgs)  
          Dim extension As String = DirectCast(DataBinder.Eval(e.Item.DataItem, "Extension"), String)  
          If extension = ".swf" Then 
              Dim flashPanel As Panel = DirectCast(e.Item.FindControl("flashPanel"), Panel)  
              flashPanel.Visible = True 
              Dim imagePanel As Panel = DirectCast(e.Item.FindControl("imagePanel"), Panel)  
              imagePanel.Visible = True 
          End If 
      End Sub 

      **The checks are only necessary when alternating between images and flash banners. Otherwise you just use one panel.


    The Page.ResolveUrl method is used where we cast the object value of the flash banner to a string as return value:

    src='<%# Page.ResolveUrl((string)DataBinder.Eval(Container.DataItem, "ImageAddress")) %>'    


    src='<%# Page.ResolveUrl(DirectCast(DataBinder.Eval(Container.DataItem, "ImageAddress"), String)) %>' 




  • rasul
    rasul avatar
    3 posts
    Member since:
    Jul 2007

    Posted 23 May 2008 Link to this post

    Hi, could you do a favor and send vb version please?
  • Sophy
    Sophy avatar
    636 posts

    Posted 26 May 2008 Link to this post

    Hi Rasul,

    Please, find the CodeLibrary updated with a VB version in the attached archive.
    Let us know if you need further assistance.

    Sincerely yours,
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  • rasul
    rasul avatar
    3 posts
    Member since:
    Jul 2007

    Posted 08 Jun 2008 Link to this post

    Hi Sophi, thanks for your quick reply, but i have a question,
    I have created a photo album that contains two pages:
    1)Albums: which shows my albums with a stored procedure that select albums from Albums table and show them in a data list (using dataset)

    my problem is how can i show the first photo of each Albums in the Datalist,
    Please Help
  • Sophy
    Sophy avatar
    636 posts

    Posted 12 Jun 2008 Link to this post

    Hello Rasul,

    Please, open a support ticket and describe in details your scenario and the problems you experience. I would also like to ask you send us your test pages which demonstrate your exact scenario so that we can get a better idea of what you want to achieve.
    For your convenience I have attached a screenshot with instructions how to open a support ticket.

    Kind regards,
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  • Back to Top