SIGN UP MEMBER LOGIN:    
ARTICLE

Make Photo Slideshow using JQuery

Posted by Raj Kumar Articles | JQuery January 10, 2011
This article will describes how to make and run image slideshow with the help of JQuery.
Reader Level:
 

This article will describes how to make and run image slideshow with the help of JQuery. I am using PrettyPhoto JQuery in this sample. PrettyPhoto is a free JQuery project, I used to build this nice photo gallery.

First of all, create a new ASP.NET website and provide your website name, browse saving location of website and click OK button.

This will create a website.

After that, add three folders named - javascripts, styles, and images.

Here I am explaining two methods to make an image gallery. The first method is direct display images using img HTML control.  The second method is using a DataList control and bind photos at runtime. 

First of all add js files in javascript folder and stylesheet in styles folder and images in images folder and call js file and css file on page like this.

Call JS and CSS in inside of head tag like this.

<head runat="server">

    <title>JQuery Photo Slideshow Example</title>

    <link rel="stylesheet" type="text/css" href="styles/prettyPhoto.css"  charset="utf-8" media="screen" />       

    <!-- Arquivos utilizados pelo jQuery lightBox plugin -->

    <script type="text/javascript" src="javascripts/jquery-1.3.2.min.js" charset="utf-8"></script>

    <script type="text/javascript" src="javascripts/jquery-1.4.4.min.js" charset="utf-8"></script>

    <script type="text/javascript" src="javascripts/jquery.prettyPhoto.js" charset="utf-8"></script>

</head>

Here I am using two options if you want to fetch images from database then you can use DataList control and if you want to show direct in HTML IMG control then choose first option.

This is using IMG HTML Control

<div>

    <h3>Using IMG HTML Control</h3>

    <a href="images/fullscreen/1.jpg" rel="prettyPhoto[pp_gal]" title="You can add caption to pictures."><img src="images/thumbnails/t_1.jpg" width="60" height="60" alt="Red round shape" /></a>

    <a href="images/fullscreen/2.jpg" rel="prettyPhoto[pp_gal]"><img src="images/thumbnails/t_2.jpg" width="60" height="60" alt="Nice building" /></a>

    <a href="images/fullscreen/3.jpg" rel="prettyPhoto[pp_gal]"><img src="images/thumbnails/t_3.jpg" width="60" height="60" alt="Fire!" /></a>

    <a href="images/fullscreen/4.jpg" rel="prettyPhoto[pp_gal]"><img src="images/thumbnails/t_4.jpg" width="60" height="60" alt="Rock climbing" /></a>

    <a href="images/fullscreen/5.jpg" rel="prettyPhoto[pp_gal]"><img src="images/thumbnails/t_5.jpg" width="60" height="60" alt="Fly kite, fly!" /></a>

    </div>   

   

 

This is using DataList data control.

 

<div>

    <h3>Using DataList</h3>

    <asp:DataList ID="galleryDataList" RepeatColumns="5" runat="server">

      <ItemTemplate>

       <a href='<%# Eval("Name","images/fullscreen/{0}")%>' rel="prettyPhoto[pp_gal]" title="You can add caption to pictures.">                               

        <img src='<%# Eval("Name","images/fullscreen/{0}")%>' width="60" height="60" alt='<%# Eval("Name") %>' />

       </a>

      </ItemTemplate>

    </asp:DataList>

  </div>

 

As you can see everything is same as image gallery sample now the only diffrence is this script, call this script after closing of Body tag.

 

<script type="text/javascript" charset="utf-8">

        $(document).ready(function() {

            $("a[rel^='prettyPhoto']").prettyPhoto({ theme: 'facebook', slideshow: 5000, autoplay_slideshow: true });

        });

        </script>

 

Code Behind:

 

using System.IO;

 

protected void Page_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

            DirectoryInfo myImageDir = new DirectoryInfo(MapPath("~/images/fullscreen/"));

            try

            {

                galleryDataList.DataSource = myImageDir.GetFiles();

                galleryDataList.DataBind();

            }

            catch (System.IO.DirectoryNotFoundException)

            {

                Response.Write("<script language =Javascript> alert('Error!');</script>");

            }

        }

    }

 

Build and Run

Now time to run the application to see the result. The output looks like Image 1.

1.jpg

Image1.

Now click on any image then image should be open in new window and wait little bit all images show come in slideshow with previous,next option.


2.jpg

Image2.

As you can see images are rotating itself just wait little bit.

Login to add your contents and source code to this article
share this article :
post comment
 

Could u show how to give some space between consecutive photos?? and thanks for this ...... after hours of searching this saved my project :)

Posted by Aniruddha Jan 08, 2012

hey this is awesome....thanx alot for sharing it with us!!!!!!!!!!!happy .netting

Posted by yoky yoky Sep 27, 2011

I implement this in my proj. It looks fine.

Posted by Nipesh Shah Feb 15, 2011

put you subfolder path here.. DirectoryInfo myImageDir = new DirectoryInfo(MapPath("~/images/fullscreen/"));

Posted by Raj Kumar Jan 11, 2011

could u help on this article implement with multiple folder and subfolder check this link http://www.c-sharpcorner.com/UploadFile/desaijm/asp_net_photoalbum02122006183031PM/asp_net_photoalbum.aspx thanks Kaushal

Posted by Kaushal Kumawat Jan 11, 2011
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor