i




 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Web Project ajax slide show in asp.net
10-19-2010, 06:41 PM (This post was last modified: 10-19-2010 06:49 PM by nisar87.)
Post: #1
ajax slide show in asp.net
Simple demonstration of ajax slide show

Required Tools: vs 2005, ajax toolkit, sqlserver 2008

Description:
I made simple slide show using SlideShowExtender from ajaxtoolkit, and load images from database, to control slide show i developed play,stop,next,prv buttons.
Code:
<ajax: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" />

and set default image in slideshow on page_load event
Code:
protected void Page_Load(object sender, EventArgs e)
    {
        if (this.IsPostBack)
            return;

        tblData = dbobj.FetchData();

        // set the initial image
        if (tblData.Rows.Count > 0)
        {
            string imgPath = tblData.Rows[0]["imagepath"].ToString();
            imgShowImage.ImageUrl = "image/" + imgPath;
        }
    }

And wrote a service method to generate a complete slideshow from paths which stored in database and this method is called in SlideShowServiceMethod="GetSlides" aspx page
Code:
[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];
            imagepath = dr["imagepath"].ToString();
            slides[i] = new AjaxControlToolkit.Slide("image/" + imagepath, "Image name", "Image Description");
        }
        return slides;
    }
Note: i uploaded this project in my google doc because its size increased the limit of forum attachment
Please feel free to ask questions.

Complete project with database backup attachment:
Download Ajax SlideShow Project



[Image: 2604595733.png]
Quote
10-20-2010, 12:27 AM
Post: #2
RE: ajax slide show in asp.net
seems to be good. but not working in my VS 2010. Anyway its work on vs 2005. I think some problem of AjaxControlToolKit.
good post nisar.


Thanks and Regards
Raju
Quote
10-20-2010, 02:29 AM (This post was last modified: 10-20-2010 02:49 AM by balkis.)
Post: #3
RE: ajax slide show in asp.net
Hi nisar,
i'm still not getting the solution..

this is my class
Code:
public class Categories
    {
        public DataTable FetchData()
        {
            SqlConnection con;
            SqlCommand cmd;
            DataTable tblData = new DataTable();            

            con = new SqlConnection("Server=(local); Database=test; user id=sa;  password=itdept");
            string cmdString = "SELECT * FROM image";
            cmd = new SqlCommand(cmdString, con);
            con.Open();

            SqlDataAdapter da = new SqlDataAdapter(cmd);
            tblData = new DataTable();
            da.Fill(tblData);
            con.Close();
            return tblData;
        }
    }
and this is the code
Code:
private static DataTable tblData = new DataTable();

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

        Categories cc = new Categories();
        tblData = cc.FetchData();      

        // set the initial image
        if (tblData.Rows.Count > 0)
        {
            string imgPath = tblData.Rows[0]["imagePath"].ToString();
            imgShowImage.ImageUrl = "image/" + imgPath;
        }
    }

    [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];
            imagepath = dr["imagePath"].ToString();
            slides[i] = new AjaxControlToolkit.Slide("image/" + imagepath, "imageID", "Description");
        }
        return slides;
    }
now, no error appear but no image is display..huhu..
Quote
10-20-2010, 02:37 AM (This post was last modified: 10-20-2010 02:39 AM by raju.)
Post: #4
RE: ajax slide show in asp.net
Did you check images in "image" folder?
above example is work fine. Nisar added the attachment file with Database backup file. Please download and check with VS 2005. if you still getting error i will takecare of that.


Thanks and Regards
Raju
Quote
10-20-2010, 03:01 AM (This post was last modified: 10-20-2010 03:49 AM by balkis.)
Post: #5
RE: ajax slide show in asp.net
i see..
no wonder why the image is not display..
nisar image path is directly to the image but mine is
Code:
C:\Users\itdept\Desktop\webmaster\image\Lighthouse.jpg
...

when i try to remove all the path and have only have the name of the image, it run successfully..

is there any ways to read the long path?
the path is automatically generate when uploading the image into database..
btw, it is a good post..
thanks to all for helping Smile
Quote
10-20-2010, 03:43 AM
Post: #6
RE: ajax slide show in asp.net
Hi,
I have checked with VS 2005 it is working fine.

Good Post Nisar.... Smile

Please give reputation if my answer/post is useful for you
Best Regards
Arti Gupta
Quote
10-20-2010, 04:42 AM (This post was last modified: 10-20-2010 04:58 AM by nisar87.)
Post: #7
RE: ajax slide show in asp.net
yes bakis, you can still run with long path.

Remove image/ from below line.
imgShowImage.ImageUrl = "image/" + imgPath;

and second thing, how you are getting below path, webmaster is your solution folder?
C:\Users\itdept\Desktop\webmaster\image\Lighthouse.jpg

because normally javascript or in ajax, the solution folder works. if above path is saved in your database and image folder is in your solution then you need to split the path.
A quick solution to get image name from your path.
Code:
string FPath = @"C:\Users\itdept\Desktop\webmaster\image\Lighthouse.jpg";
        string[] spliter = System.Text.RegularExpressions.Regex.Split(FPath, "image");
        FPath=spliter[1].TrimStart('\\');

in your case the code will be like this

Code:
private static DataTable tblData = new DataTable();

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

        Categories cc = new Categories();
        tblData = cc.FetchData();      

        // set the initial image
        if (tblData.Rows.Count > 0)
        {
            string FPath = tblData.Rows[0]["imagePath"].ToString();
        //string FPath = @"C:\Users\itdept\Desktop\webmaster\image\Lighthouse.jpg";
        string[] spliter = System.Text.RegularExpressions.Regex.Split(FPath, "image");
        FPath=spliter[1].TrimStart('\\');
            imgShowImage.ImageUrl = "image/" + FPath;
        }
    }

    [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];
            imagepath = dr["imagePath"].ToString();
        //string FPath = @"C:\Users\itdept\Desktop\webmaster\image\Lighthouse.jpg";
        string[] spliter = System.Text.RegularExpressions.Regex.Split(imagepath , "image");
        imagepath =spliter[1].TrimStart('\\');
            slides[i] = new AjaxControlToolkit.Slide("image/" + imagepath, "imageID", "Description");
        }
        return slides;
    }

if still confuse then please attach your code in zip format in question/answer section.
@Raju:
Quote:seems to be good. but not working in my VS 2010

yes toolkit in VS2010 have a different version and compatible with framework 4.0. but i think by changing the reference and modifying the webconfig file is enough to run the same solution in VS2010

[Image: 2604595733.png]
Quote
10-20-2010, 06:30 AM (This post was last modified: 10-20-2010 06:34 AM by balkis.)
Post: #8
RE: ajax slide show in asp.net
i also find another ways to upload only filename into database, so that long path is not the problem now..
btw i also tried ur ways, it also run successfully..
very3 good solution
thanks nisar Big Grin
Quote
10-20-2010, 06:33 AM
Post: #9
RE: ajax slide show in asp.net
Thanks.... Big Grin
Stay in our forum as a family Smile

[Image: 2604595733.png]
Quote
11-10-2010, 11:38 AM
Post: #10
RE: ajax slide show in asp.net
Nice posting ,,but am not able to play the slides could you please tell me how can we do it..

“A mind stretched by a new idea can never go back to its original dimension.”

Quote
11-10-2010, 12:38 PM
Post: #11
RE: ajax slide show in asp.net
to play this slide show, you need VS 2005 with ajax toolkit
and please let me know what sort of problem you are facing?
any error?

[Image: 2604595733.png]
Quote
11-10-2010, 12:42 PM
Post: #12
RE: ajax slide show in asp.net
ok am using vs2008 but i not installed ajaxtoolkit let me try with it..

“A mind stretched by a new idea can never go back to its original dimension.”

Quote
11-10-2010, 12:47 PM
Post: #13
RE: ajax slide show in asp.net
ok, no problem, ajax slide show is the control of ajax toolkit, for properly running this is VS 2008, you need to modify webconfig, because in VS 2008 the toolkit version is separate, but let me know if you have problem in running this, i will modify the code according to VS2008 for you Smile

[Image: 2604595733.png]
Quote




User(s) browsing this thread: 1 Guest(s)