Click here to Skip to main content
16,018,264 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello all !!


i have retreived images from database using c# but how can i show them in a javascript slideshow in my .aspx page?
Posted

The client and JS code don't have access to the database (hopefully that's obvious). So you need to provide a server script to load an image from the database and return it as a HTTP 'file', and then have the JavaScript load that URL.

I've not actually done this in ASPX so pseudocode only, but what you need to do is something like
int id = Page.QueryVars["id"];
DataTable dt = query("select mimetype, image from images where imageid="+id);
switch(dt.RowCount){
 case 1:
  // Return the image
  Response.MimeType = (string)dt[0]["mimetype"];
  Response.Write((byte[])dt[0]["image"]);
  break;
 case 0:
  Response.Code = 404;
  break;
 default:
  Response.Code = 500;
  Response.Write("Unexpected duplicate image id "+id);
  break;
}


Then you would call it by retrieving getimage.aspx?id=5.

Hopefully someone who's actually done this in ASPX can fill this out a bit more. (I've done something similar in PHP where the algorithm is the same but obviously the code is completely different.)
 
Share this answer
 
Comments
Amir Mahfoozi 3-Nov-11 11:07am    
Agree with you
If u are having the images in folder then following javascript will work fine

XML
<script type='text/javascript'
    src='http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js'>
    </script>
    <script type="text/javascript">
        var imgs = [
        'images/04.jpg',
        'images/img1.png',
        'images/user_icon.jpg'];
        var cnt = imgs.length;

        $(function() {
            setInterval(Slider, 3000);
        });

        function Slider() {
        $('#imageSlide').fadeOut("slow", function() {
           $(this).attr('src', imgs[(imgs.length++) % cnt]).fadeIn("slow");
        });
        }

</script>

if u want to show database retrived images then call the javascript function from .aspx.cs and pass the images[] to javascript function . what i mean to say is something as:
C#
Page.RegisterStartupScript("aaa", "<script language='javascript'>sendimages('" + imgpaths + "');</script>");
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900