"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Friday, September 16, 2011

Binding or display image having zoom effect from folder

Hi *.*,
As a continuation of my previous post. Now i'm binding images from folder.

Code 
    private class ImageFileInfo
    {
        public string FileName { get; set; }
    }

    public void limage()
    {
        string imgFolder = HttpContext.Current.Request.PhysicalApplicationPath + @"img\";
        string[] fileEntries = Directory.GetFiles(imgFolder);
        List<ImageFileInfo> mylist = new List<ImageFileInfo>();
        foreach (string fName in fileEntries)
        {
            string d = System.IO.Path.GetFileName(fName);
            mylist.Add(new ImageFileInfo { FileName = d });
        }
        dtagrid.DataSource = mylist;
        dtagrid.DataBind();
    }
 

On HTML
 
                <asp:DataList ID="dtagrid" runat="server" RepeatColumns="5" RepeatDirection="Horizontal">
                    <ItemTemplate>
                        <li><a href='img/<%# Eval("FileName") %>'>
                            <img src='img/<%# Eval("FileName") %>' alt="" /></a></li>
                    </ItemTemplate>
                </asp:DataList>

 U can download a demo from here
 Stay Tune...
Have a nice day... 'N happy Coding :)

No comments: