Loading Images/FlashBanners in Rotator from DataBase

Thread is closed for posting
5 posts, 0 answers
  1. 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 15 Aug 2007 Link to this post

    Requirements

    RadControls version

    RadRotator v.2.62+

    .NET version

    ASP.NET 2.0

    Visual Studio version

    VS2005

    programming language

    C#,VB

    browser support

    all browsers supported by RadControls


     
  2. PROJECT DESCRIPTION
    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.

    STEPS:

    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">  
          <frametemplate> 
              <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">  
                  </embed> 
                      </object> 
                  </asp:panel> 
                  <asp:panel runat="server" id="imagePanel" visible="false">  
                      <img id="Images" runat="server" alt="" class="RotatorImage" src='<%# DataBinder.Eval(Container.DataItem, "ImageAddress") %>' /> 
                  </asp:panel> 
              </div> 
          </frametemplate> 
      </radr:radrotator> 

    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:
      C#

      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;  
          }  
          else 
          {  
              Panel imagePanel = (Panel)e.Item.FindControl("imagePanel");  
              imagePanel.Visible = true;  
          }  
       

      VB

      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 
          Else 
              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.

    QUICK NOTES:

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

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

    VB

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

     

     

     

  • D327890D-DBFB-4711-9927-06755FB9370E
    D327890D-DBFB-4711-9927-06755FB9370E 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?
  • E9CFDAAB-168D-40FF-82EE-B5BB43C9B7FA
    E9CFDAAB-168D-40FF-82EE-B5BB43C9B7FA avatar
    636 posts
    Member since:
    Sep 2012

    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,
    Sophy
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  • D327890D-DBFB-4711-9927-06755FB9370E
    D327890D-DBFB-4711-9927-06755FB9370E 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)
    2)Photos

    my problem is how can i show the first photo of each Albums in the Datalist,
    Please Help
  • E9CFDAAB-168D-40FF-82EE-B5BB43C9B7FA
    E9CFDAAB-168D-40FF-82EE-B5BB43C9B7FA avatar
    636 posts
    Member since:
    Sep 2012

    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,
    Sophy
    the Telerik team

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

    This Code Library is part of the product documentation and subject to the respective product license agreement.