Skip to main content

Show Images in Slide using AJAX Control

Show Images in Slide using AJAX Control

We can use AJAX Slide show extender once load all data in to data table once and assign each images as slide for ajax slide show extender control.
To perform this task we need to write an web service to show the images on image control.
The code snippet is provided below:

Design side:
<asp:SlideShowExtender ID="SlideShowExtender1" runat="server" TargetControlID="Image1" PlayInterval="2000" SlideShowServiceMethod="GetSlides" AutoPlay="true" 
                        NextButtonID="btnNext" PreviousButtonID="btnPrev" PlayButtonID="btnPlay" PlayButtonText="Play"
                        StopButtonText="Stop" Loop="true">
</asp:SlideShowExtender>
 <asp:Button ID="btnPrev" runat="server" Text="Previous" />  <asp:Button
                        ID="btnPlay" runat="server" Text="Play" />  <asp:Button
                            ID="btnNext" runat="server" Text="Next"/>
 

As i written web service  code in same file, to show just the concept....
The better way is to write/create new web service and write the method in web service to get images array.
Write a Web Service which will 
read the image file paths from the database and create an array of 
AjaxControlToolkit.Slide[]. In the SlideShowServiceMethod propery of the
 SlideShowExtender control specify the web method. 
 
Code behind:
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;

public partial class _Default : System.Web.UI.Page 
{
    SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["Con"].ConnectionString);
    SqlCommand sqlcmd = new SqlCommand();
    SqlDataAdapter da = new SqlDataAdapter();
    public static DataTable dt = new DataTable();
    string path;  
   
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static AjaxControlToolkit.Slide[] GetSlides()
{   
     //Load your data into data table from database once
    //If path is stored in database then use below code 
    if (dt.Rows.Count > 0)
    {
       AjaxControlToolkit.Slide[] imgSlide = new AjaxControlToolkit.Slide[dt.Rows.Count];
        for (int i = 0; i <= dt.Rows.Count - 1; i++)
        {
           imgSlide[i] = new AjaxControlToolkit.Slide(dt.Rows[i][1].ToString(), "", "");
        }
       return (imgSlide);
    }
    else
    {
        AjaxControlToolkit.Slide[] imgSlide1 = new AjaxControlToolkit.Slide[dt.Rows.Count];
        return (imgSlide1);
    }
}   
}
 
 
This is how it works.......
Thanks..........................

Comments

Popular posts from this blog

Creating package in Oracle Database using Toad For Oracle

What are Packages in Oracle Database A package is  a group   of procedures, functions,  variables   and  SQL statements   created as a single unit. It is used to store together related objects. A package has two parts, Package  Specification  and Package Body.

Resolving 'Setup Account Privileges' error while installing SQL Server

A new installation of Microsoft SQL Server 2012 or Microsoft SQL Server 2008 R2 fails You see the following error message when you try to install a new instance of SQL Server 2012 or SQL Server 2008 R2: Rule "Setup account privileges" failed.

Creating Oracle stored Procedures using TOAD for Oracle

In a database management system, a  stored procedure  is a set of Structured Query Language (SQL) statements with an assigned name that's stored in the database in compiled form so that it can be shared by a number of programs. The use of  stored procedures  can be helpful in controlling  access to data, preserving  data integrity  and  improving  productivity.