ASP.NET - Ajax Slideshow  ASP.NET - Ajax Slideshow

Asked By Arth Srivastava
01-Dec-08 12:44 AM

Hi All,

 I am using the Ajax Slideshow from asp.net/ajax samples.....

the sample code is working fine...

 

But i want to fetch the images from either Database or from the Project/Images folder.

I do not want to hard code the image names like in the Samples of ajax ...as given below:

 

 

 

<script runat="Server" type="text/C#">

[System.Web.Services.WebMethod]

[System.Web.Script.Services.ScriptMethod]

public static AjaxControlToolkit.Slide[] GetSlides()

{

AjaxControlToolkit.Slide[] slides = new AjaxControlToolkit.Slide[5];

slides[0] = new AjaxControlToolkit.Slide("images/Blue hills.jpg", "Blue Hills", "Go Blue");

slides[1] = new AjaxControlToolkit.Slide("images/Sunset.jpg", "Sunset", "Setting sun");

slides[2] = new AjaxControlToolkit.Slide("images/Winter.jpg", "Winter", "Wintery...");

slides[3] = new AjaxControlToolkit.Slide("images/Water lilies.jpg", "Water lillies", "Lillies in the water");

slides[4] = new AjaxControlToolkit.Slide("images/VerticalPicture.jpg", "Sedona", "Portrait style picture");

return(slides);

}

</script>

&nbsp; &nbsp;<br />

<br />

<asp:Image ID="Image1" runat="server" Height="316px" Width="388px" /><br />

<br />

<asp:Label ID="lblImageDescription" runat="server" /><br />

<br />

<asp:Button ID="Btn_Previous" runat="server" Text="Previous" />

<asp:Button ID="Btn_Next" runat="server" Text="Next" Width="64px" /><br />

<br />

<asp:Button ID="Btn_Play" runat="server" Text="Play" /><br />

<cc1:SlideShowExtender ID="SlideShowExtender1"

AutoPlay="true" ImageDescriptionLabelID="lblImageDescription"

Loop="true" NextButtonID="Btn_Next" PlayButtonID="Btn_Play"

PlayButtonText="Play" PreviousButtonID="Btn_Previous"

SlideShowServiceMethod="GetSlides" StopButtonText="Stop"

TargetControlID="Image1" runat="server">

</cc1:SlideShowExtender>

 

<script runat="Server" type="text/C#">
        [System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public static AjaxControlToolkit.Slide[] GetSlides()
        {
            AjaxControlToolkit.Slide[] slides = new AjaxControlToolkit.Slide[5];

            slides[0] = new AjaxControlToolkit.Slide("images/Blue hills.jpg", "Blue Hills", "Go Blue");
            slides[1] = new AjaxControlToolkit.Slide("images/Sunset.jpg", "Sunset", "Setting sun");
            slides[2] = new AjaxControlToolkit.Slide("images/Winter.jpg", "Winter", "Wintery...");
            slides[3] = new AjaxControlToolkit.Slide("images/Water lilies.jpg", "Water lillies", "Lillies in the water");
            slides[4] = new AjaxControlToolkit.Slide("images/VerticalPicture.jpg", "Sedona", "Portrait style picture");
            return(slides);
        }
    </script>

            &nbsp; &nbsp;<br />
            <br />
            
            <asp:Image ID="Image1" runat="server" Height="316px" Width="388px" /><br />
            <br />
            
            <asp:Label ID="lblImageDescription" runat="server" /><br />
            <br />
    
    
            <asp:Button ID="Btn_Previous" runat="server" Text="Previous" />
            <asp:Button ID="Btn_Next" runat="server" Text="Next" Width="64px" /><br />
            <br />
            <asp:Button ID="Btn_Play" runat="server" Text="Play" /><br />
            
    
            <cc1:SlideShowExtender ID="SlideShowExtender1"
              AutoPlay="true" ImageDescriptionLabelID="lblImageDescription"
               Loop="true" NextButtonID="Btn_Next" PlayButtonID="Btn_Play" 
                PlayButtonText="Play" PreviousButtonID="Btn_Previous" 
                 SlideShowServiceMethod="GetSlides" StopButtonText="Stop"
                  TargetControlID="Image1" runat="server">
            </cc1:SlideShowExtender>
 
Please answer very very earliest.....
Thanks ,
Arth

Getting the Image from Database  Getting the Image from Database

01-Dec-08 12:50 AM
' This function returns the image retrieved from the database

Private Function GetImageFromDB(ByVal ImageID As Integer) As Image
Dim image As Image
...
...

Try
sqlCommand = "SELECT Image FROM ImageTable WHERE ImageID = "_
+ ImageID.ToString()

...

Dim dr As SqlDataReader
dr = cmd.ExecuteReader()
While (dr.Read())

Dim byt As Byte()
byt = dr.Item(strImage)
' Convert the image bytes to System.Drawing.Image

Dim bmp As New Bitmap(New System.IO.MemoryStream(byt))
image = bmp

End While

...

End Try

Return image

End Function

Fetch Images nd display in the Gridview  Fetch Images nd display in the Gridview

01-Dec-08 12:51 AM
Hi, I will suggest u to do some thing like this.Pass the Query like this while Fetchinh the Data in the Gridview

Select FolderName+'\'+ImageName As Path form Table

and give like DataBinder.Eval(Container.DataItem, "
Path ")
If that Image is inside the Folder than

src=../
<%#DataBinder.Eval(Container.DataItem, "Path ")%>

If there are more than Two folder then

src=../../<%#DataBinder.Eval(Container.DataItem, "Path ")%>
Just check the Path where is that Image and assign like that,thats all. Thanks

It's Pretty easy. Use this.  It's Pretty easy. Use this.

01-Dec-08 12:54 AM

I assume that you can write a DB Procedure that returns data from db (retrieveDataFromdb) as below.

And i assume that you can retireve the entire path in first column (dr[0])

DataSet dataSet = retrieveDataFromdb();        AjaxControlToolkit.Slide[] slide = new AjaxControlToolkit.Slide[dataSet.Tables[0].Rows.Count];
        int index = 0;
        foreach (DataRow dr in dataSet.Tables[0].Rows)
        {
            slide[index++] = new AjaxControlToolkit.Slide(dr[0].ToString);
        }
        dataSet.Dispose();

Ajax Toolkit Slide Show with Images From SQL Database Table  Ajax Toolkit Slide Show with Images From SQL Database Table
01-Dec-08 12:54 AM

Following our tutorial of inserting images into the database I will now show you how to display images in a slide show with the Ajax Toolkit Slide Show Extender.

 

The Slide Show Extender usually works by providing the slideshow with images on the file system that are placed inside objects called Slide’s. These Slide objects are then displayed sequentially on the Slide Show with options to stop, re-play, and choose next and previous images.



So if images from the Slide Show Extender can only use file system images, how can we display images from the database table that are in the form of image bytes?

 

The trick is to use the PreviewImage.aspx (from previous tutorial) as a replacement in the image path url of the Slide constructor and append to it the image id. So when the Slide Show starts playing, each slide that is about to be displayed will in fact:

 

1.       Call this PreviewImage.aspx file

2.       The image will be fetched from the database table

3.       PreviewImage.aspx renders the image to screen

 

 

The PreviewImage.aspx in essence acts like the physical file image as it retrieves and writes the image bytes to screen without needing to store the image on the file system.

 

Below is the code to get images from the file system and display it in the Slide Show.

 

    [System.Web.Services.WebMethod]

    [System.Web.Script.Services.ScriptMethod]

    public static Slide[] GetSlidesFileSystem()

    {

        string imageFolder = @"C:\randomimages";

        DirectoryInfo directory = new DirectoryInfo(imageFolder);

        Slide[] slides = null;

 

        if (directory.Exists)

        {

            FileInfo[] images = directory.GetFiles("*.jpg");

            slides = new Slide[images.Length];

 

            int i = 0;

 

            foreach (FileInfo image in images)

            {

                string title = image.Name;

                string imagePath = image.FullName;

 

                slides[i] = new Slide(imagePath, title, title);

                i++;

            }

        }

 

        return slides;

    }

 

The full name of the file includes the full path to where the file is located. So when the slide show is played, we can directly reference the image from the full file path then display it. When we use images from the database table, we cannot reference the image from the database directly. The database image is a series of bytes so it is not really an image until we convert it to one. If we wanted to take the same approach as above, we need to read through the database table and save all the images on to the file system.

 

In order to display the images from the database the only thing we need to add as the image path is the reference to the file PreviewImage.aspx concatenated with the image id.

 

    [System.Web.Services.WebMethod]

    [System.Web.Script.Services.ScriptMethod]

    public static Slide[] GetSlides()

    {

        DataTable dt = ImageTransactions.RetrieveAllImagesFromDatabase();

 

        Slide[] slides = null;

 

        if (dt.Rows.Count > 0)

        {

            slides = new Slide[dt.Rows.Count];

 

            int i = 0;

 

            foreach (DataRow dr in dt.Rows)

            {

                int id = (int)dr["id"];

                string title = (string)dr["title"];

                string imagePath = string.Format("PreviewImage.aspx?id={0}", id);

 

                slides[i] = new Slide(imagePath, title, title);

                i++;

            }

        }

 

        return slides;

    }

 

Installing the Ajax Control Toolkit

 

Download it from http://www.codingdotnet.com/blog/ct.ashx?id=08167750-a3aa-44e0-8a73-1c28f6b3b575&url=http%3a%2f%2fwww.asp.net%2fajax%2fdownloads%2f (for .Net Framework 3.5)

 

Steps:

1.       Extract the Ajax Control Toolkit project

2.       Build the project

3.       Now the AjaxControlToolkit.dll will be in the bin directory

4.       In the project, add a reference to the AjaxControlToolkit.dll file

5.       On the Default.aspx page, make a reference to the AjaxControlToolkit

 

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ToolKit" %>

 

There you have it, an easy way to display images from a database table using the Ajax Toolkit Slide Show Extender.
Try this  Try this
01-Dec-08 01:32 AM
<ajaxToolkit:SlideShowExtender ID="SlideShowExtender1" runat="server" 
    TargetControlID="Image1" 
    SlideShowServiceMethod="GetSlides" 
    AutoPlay="true" 
    ImageTitleLabelID="imageTitle"
    ImageDescriptionLabelID="imageDescription"
    NextButtonID="nextButton" 
    PlayButtonText="Play" 
    StopButtonText="Stop" 
    PreviousButtonID="prevButton" 
    PlayButtonID="playButton" 
    Loop="true" /> •SlideShowServicePath - Path to the webservice that the extender will pull the images from. 
•SlideShowServiceMethod - The webservice method that will be called to supply images. The signature of the method must match this: 
    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public AjaxControlToolkit.Slide[] GetSlides() { ... }Note that you can replace "GetSlides" with a name of your choice, but the return type and parameter name and type must exactly match, including case. 
•ContextKey - User/page specific context provided to an optional overload of the web method described by ServiceMethod/ServicePath. If the context key is used, it should have the same signature with an additional parameter named contextKey of type string: 
    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public AjaxControlToolkit.Slide[] GetSlides(string contextKey) { ... }Note that you can replace "GetSlides" with a name of your choice, but the return type and parameter name and type must exactly match, including case. 
•UseContextKey - Whether or not the ContextKey property should be used. This will be automatically enabled if the ContextKey property is ever set (on either the client or the server). If the context key is used, it should have the same signature with an additional parameter named contextKey of type string (as described above). 
•NextButtonID - ID of the button that will allow you to see the next picture. 
•PlayButtonID - ID of the button that will allow you to play/stop the slideshow. 
•PreviousButtonID - ID of the button that will allow you to see the previous picture. 
•PlayButtonText - The text to be shown in the play button to play the slideshow. 
•StopButtonText - The text to be shown in the play button to stop the slideshow. 
•PlayInterval - Interval in milliseconds between slide transitions in play mode. 
•ImageTitleLabelID - ID of Label displaying current picture's title. 
•ImageDescriptionLabelID - ID of Label describing current picture. 
•Loop - Setting this to true will allow you to view images in a round-robin fashion. 
•AutoPlay - Setting this to true will play the slideshow automatically on render
Create New Account
help
Net hi friends Any one send frequently asked Important questions in C# .Net, ADO .Net, Asp .Net and Sql Server. . . . . . . . tx in Advance. . . . . . Hi, Find this. . (B)What is an IL? (B A) What is scavenging? (B) What are different types of caching using cache object of ASP.NET? (B) How can you cache different version of same page using ASP.NET cache object? (A) How will implement Page Fragment Caching? (B) Can you compare ASP.NET sessions with classic ASP? (B) Which are the various modes of storing ASP.NET session
in Sql server as var_name int How do you separate business logic while creating an ASP.NET application? There are two level of asp.net debugging 1. Page level debugging For this we have to edit the page level debugging The control itself will take care of the date display How can you deploy an asp.net application ? You can deploy an ASP.NET Web application using any one of the following three deployment options. a) Deployment using VS
Migration from ASP to ASP.net How to convert ASP site to ASP.NET site using C# http: / / www.asp.net / downloads / archived-v11 / migration-assistants / asp-to-aspnet hi, ASP.NET framework is very much different from unstrucured ASP and there is no correct way to
Tracing in ASP.NET? hi all, what is tracing? how to achieve tracing in asp.net? different ways of doing tracing? thanks and regards Aman Khan hi. . Tracing in ASP.NET 2.0 Tracing is a way to monitor the execution of your ASP.NET application. You can record exception details and program flow in a way that doesn't