Ajax Image Slide Show

In most website image slide show is required, and in some website images path are saved in database, so they need to make slide show of those images which exist in database for this purpose i am going to present a code how to make slide show from those picture which path is saved in database by using ajax toolkit + mysql

In aspx page i use SlideShowExtender, you can use this by adding ajax toolkit in your project,


I also make four image button like play, stop, prv,next, By using this button you can handle complete slide show

Now come to CS page, in CS page on page load i retrieve image from database and fill in datatable, why i split and why not to split, these answer are written below where i use split function, Please if you have any query, feel free to ask

##################################### CS page ##############################


//suppose your image folder name is "TempImages"


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using FidesTech;

public partial class SlideShowTest : System.Web.UI.Page
{
private static DataTable tblData = new DataTable();

protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
return;

DBConnection db = new DBConnection();
string strSQL = "SELECT tbl_advertisment.ImagePath FROM tbl_advertisment";
MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection(ConfigurationManager.AppSettings["connectionString"]);
conn.Open();

MySql.Data.MySqlClient.MySqlCommand comm = new MySql.Data.MySqlClient.MySqlCommand(strSQL, conn);
MySql.Data.MySqlClient.MySqlDataAdapter da = new MySql.Data.MySqlClient.MySqlDataAdapter(comm);
tblData = new DataTable();
da.Fill(tblData);
conn.Close();

// set the initial image
if (tblData.Rows.Count > 0)
{

// string seperated by '/'
// I am spliting path because in my database image path is saved like this format
//~/TempImages/image.jpg
//If you store your images with folder name then you also split the image path
//other wise if you just store the image name like image1.jpg then you dont need
//split the image path
//

string info = tblData.Rows[0]["ImagePath"].ToString();

string[] arInfo = new string[2];

// define which character is seperating fields
char[] splitter = { '/' };

arInfo = info.Split(splitter);

imgShowImage.ImageUrl = "TempImages/" + arInfo[2];
}
}

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static AjaxControlToolkit.Slide[] GetSlides()
{
AjaxControlToolkit.Slide[] slides = new AjaxControlToolkit.Slide[tblData.Rows.Count];
string imagepath = "";
for (int i = 0; i < tblData.Rows.Count; i++)
{
DataRow dr = tblData.Rows[i];
string info = dr["ImagePath"].ToString();
string[] arInfo = new string[2];
// define which character is seperating fields
char[] splitter = { '/' };
arInfo = info.Split(splitter);
imagepath = arInfo[2];
slides[i] = new AjaxControlToolkit.Slide("TempImages/" + imagepath,"Image name","Image Description");
}
return slides;
}

}


Attachments

  • TestSlideShow.aspx (27734-17117-TestSlideShow.aspx.txt)
  • Comments

    Author: Nisar17 Apr 2009 Member Level: Gold   Points : 1

    sorry, i am little confused how to post, in this confusion i post it two times, DNS Team , please accept my apologize and delete one of my same post with the title ajax slide show

    Author: D.Jeya kumar(JK)18 Apr 2009 Member Level: Gold   Points : 0

    Hi,


    Good post using Ajax keep doing it.

    Regards
    JK

    Author: Nisar18 Apr 2009 Member Level: Gold   Points : 0

    Thanks kumar, Just need the support of you people

    Author: Rubel20 Jan 2010 Member Level: Bronze   Points : 1

    Thanx nisar..really gr8.but wat should i do when my images are not stored in database table . they are kept in a folder.

    Author: Nisar20 Jan 2010 Member Level: Gold   Points : 2

    Rubel its more easy if you pick the images from a folder

    In below function i am picking the image path from Database
    public static AjaxControlToolkit.Slide[] GetSlides()
    {

    }
    Instead of my code you can pass file names that are in folder

    string[] arrFiles = Directory.GetFiles(FolderPath);

    the above array will give you the file name that exist in folder.
    FolderPath is your folder name where images are exist.

    You can ask more if feel any problem.

    Author: Nisar18 Oct 2010 Member Level: Gold   Points : 1

    bella please post your code where you are getting error. or if you have some other issue regarding programming, join me at www.dotnetobject.com

    Guest Author: arun17 Dec 2012

    pls tell easy step to slide the picture in asp.net 2010



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: