Hi
try this example to use AJAX Slider Show to display Dynamic Image URL from database
where i save image name in my database and upload image in folder in my website root (Album folder)
Setp 1: Create database has Album table has the following fields:
Id -> PK , Idntity
Picture -> nvarchar(50)
Step2 : Create Webservice
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Collections.Generic;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
public WebService ()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
//— for slide show
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public AjaxControlToolkit.Slide[] GetSlides()
{
//———-another way————
//string strSQL = “SELECT * FROM Album”;
//SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["School_SystemConnectionString"].ConnectionString);
//conn.Open();
//SqlCommand comm = new SqlCommand(strSQL, conn);
//SqlDataAdapter da = new SqlDataAdapter(comm);
//DataTable tblData = new DataTable();
//da.Fill(tblData);
////conn.Close();
//AjaxControlToolkit.Slide[] slides = new AjaxControlToolkit.Slide[tblData.Rows.Count];
//for (int i = 0; i < tblData.Rows.Count; i++)
//{
// DataRow dr = tblData.Rows[i];
// slides[i] = new AjaxControlToolkit.Slide(“Album/” + dr["Picture"].ToString(), dr["Description"].ToString(), “”);
//}
//return slides;
//———–another way (work)——–
string strSQL = “SELECT * FROM Album”;
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["School_SystemConnectionString"].ConnectionString);
conn.Open();
SqlCommand comm = new SqlCommand(strSQL, conn);
SqlDataAdapter da = new SqlDataAdapter(comm);
DataTable tblData = new DataTable();
da.Fill(tblData);
//conn.Close();
AjaxControlToolkit.Slide[] slides = new AjaxControlToolkit.Slide[tblData.Rows.Count];
int i = 0;
foreach (DataRow row in tblData.Rows)
{
slides[i] = new AjaxControlToolkit.Slide(“Album/” + row["Picture"].ToString(), row["Description"].ToString(), “”);
i++;
}
return slides;
}
}
step3 : Create Web Form
.aspx
<asp:ScriptManager ID=”ScriptManager1″ runat=”server”>
</asp:ScriptManager>
<asp:Image ID=”imgShowImage” runat=”server”
Height=”300″
Style=”border: 1px solid black;width:auto”
AlternateText=”" />
<br />
<asp:Label runat=”Server” ID=”imageLabel1″/><br /><br />
<asp:Button runat=”Server” ID=”prevButton” Text=”Prev” Font-Size=”Larger” />
<asp:Button runat=”Server” ID=”playButton” Text=”Play” Font-Size=”Larger” />
<asp:Button runat=”Server” ID=”nextButton” Text=”Next” Font-Size=”Larger” />
<cc1:SlideShowExtender ID=”slideshowextend1″ runat=”server”
TargetControlID=”imgShowImage”
SlideShowServiceMethod=”GetSlides”
AutoPlay=”true”
ImageDescriptionLabelID=”imageLabel1″
NextButtonID=”nextButton”
PlayButtonText=”Play”
StopButtonText=”Stop”
PreviousButtonID=”prevButton”
PlayButtonID=”playButton”
Loop=”true” PlayInterval=”1000″ SlideShowServicePath=”WebService.asmx” />
.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
string strSQL = “SELECT [Picture], [Id] FROM [Album]“;
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["School_SystemConnectionString"].ConnectionString);
conn.Open();
SqlCommand comm = new SqlCommand(strSQL, conn);
SqlDataAdapter da = new SqlDataAdapter(comm);
DataTable tblData = new DataTable();
da.Fill(tblData);
conn.Close();
// set the initial image
if (tblData.Rows.Count > 0)
{
imgShowImage.ImageUrl = “Album/” + tblData.Rows[0]["Picture"].ToString();
//imageLabel1.Text = tblData.Rows[0]["Description"].ToString();
}
}
Hope it helps…
Good Luck