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;
}
}
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