Link to home
Create AccountLog in
Avatar of techsuppoprt
techsuppoprt

asked on

Help with displaying images in a table / gridview

Hi Experts!
I need some help please. I'm trying to think of the best way to populate all pictures from the folder to the page as a little photo viewer. The perfect result would be displaying a DataGrid or a 4x4 table with image thumbnails populated of every picture that's in a certain folder.
Can I possibly throw file names from the folder into the DataSet and then fill the DataGrid or is there a way to dynamically fill the table and enable the "paging" ability?
Thank you in advance.
Avatar of surajguptha
surajguptha
Flag of United States of America image

>> 4* 4 table means you will be able to display 16 pics max. / dynamically fill the table and enable the "paging" ability?

Are you looking to display every picture in the selected folder in a page?
Avatar of techsuppoprt
techsuppoprt

ASKER

Exactly  
here is a quick example for you.

Andrew

using System;
using System.Data;
using System.Configuration;
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.IO;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        foreach (FileInfo fi in new DirectoryInfo(Server.MapPath("Images")).GetFiles())
        {
            if (fi.Extension == ".jpg")
            {
                Image i1 = new Image();
                i1.Width = 100;
                i1.Height = 100;
                i1.ImageUrl = "Images/"+fi.Name;
                this.Page.Form.Controls.Add(i1);
            }
        }
    }
}
how you construct your container is up to you. Here I simply add the images to the screen but only constraining their size.  You could build on this by using the GDI+ and manipulating the images physical sizee and quality. and maybe for example stick a watermark on there.

Andrew
If the number of pictures are large, displaying all the pictures in there might be too much. I am curious, what are you trying to do? Are you just trying to display all the pictures as thumbnails when the folder is openned?
ASKER CERTIFIED SOLUTION
Avatar of REA_ANDREW
REA_ANDREW
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Thank you for your comments. FIrst solution is pretty much what I came up with myself but it doesn't really work because it's a bit too simple and just displays a list of pictures.
I need to end up with somethign like this:
http://hubblesite.org/gallery/wallpaper/
List of Hyperlink pics with  the paging ability.

Andrew, have you had any experience with that control that you posted by any chance ? It mentions that I  need to reference the evenlogdatasource.dll file but I can't figure out where to get it. The only dll that the project provides is foldercontentsdatasource.dll.