We help IT Professionals succeed at work.
Get Started

Dynamic thumbnails

vpatel2708
vpatel2708 asked
on
510 Views
Last Modified: 2012-05-05
Hello, this is bit of an extension to my last questions as it is for the same website.
I am trying to create a photography portfolio on my website.
I have coded in C# so that the full size images are dynamically loaded using the following on the Page_Load method.

        string html = "";
        char indx = 'a';
        html = "<ul>";

        foreach (FileInfo fi in new DirectoryInfo(Server.MapPath("Images/portrait")).GetFiles())
        {
            if (fi.Extension == ".jpg")
            {
                System.Web.UI.WebControls.Image i1 = new System.Web.UI.WebControls.Image();
                i1.Width = 100;
                i1.Height = 100;

                html += "<li> <a class=\"gallery slide" + indx + "\" href=\"#nogo\"> <span> <img src=\"Images/portrait/" + fi.Name +
                    "\" alt=\"APIC\"/> </span> </a> </li>";

                indx++;

            }
        }
        html += "</ul>";
        imged.Text = html;

Where imged is a literal -    <asp:literal runat="server" id="imged" />

But for the thumbnail I am using CSS so I can hover over a thumbnail and the image is displayed.
see following

#imageContainer a.gallery, #imageContainer a.gallery:visited
{
      display:block;
      color:#000;
      text-decoration:none;
      border:1px solid #000;
      margin:1px 2px 1px 2px;
      text-align:left;
      cursor:default;
}
#imageContainer a.slidea
{
      background:url(image/thumbsmall.jpg);
      background-repeat:no-repeat;      
      height:80px;
      width:80px;      
}

#imageContainer a.gallery:hover
{
      border:1px solid #FCE58B;
}

As you can see in the code about, I have to hard code in the thumbnail image, which also means a.slidea bit is also hard coded so the next image would be a.slideb.  This makes it a bit of a pain to add new images as I always have to change the code.

Can anyone help me optimise this code so I can use the hover function but dynamically specify the thumbnails too??

Thank you

protected void Page_Load(object sender, EventArgs e)
    {
        string html = "";
        char indx = 'a';
        html = "<ul>";
 
        foreach (FileInfo fi in new DirectoryInfo(Server.MapPath("Images/event")).GetFiles())
        {
            if (fi.Extension == ".jpg")
            {
                System.Web.UI.WebControls.Image i1 = new System.Web.UI.WebControls.Image();
                i1.Width = 100;
                i1.Height = 100;
 
                html += "<li> <a class=\"gallery slide" + indx + "\" href=\"#nogo\"> <span> <img src=\"Images/event/" + fi.Name + 
                    "\" alt=\"APIC\"/> </span> </a> </li>";
 
                indx++;
 
            }
        }
        html += "</ul>"; 
        imged.Text = html;
 
    }
 
   <asp:literal runat="server" id="imged" />
 
 
#imageContainer a.gallery, #imageContainer a.gallery:visited
{
	display:block;
	color:#000;
	text-decoration:none;
	border:1px solid #000;
	margin:1px 2px 1px 2px;
	text-align:left;
	cursor:default;
}
#imageContainer a.slidea
{
	background:url(image/thumbsmall.jpg);
	background-repeat:no-repeat;	
	height:80px;
	width:80px;	
}
 
#imageContainer a.slideb
{
	background:url(image/prem2.jpg);
	background-repeat:no-repeat;
	height:80px;
	width:80px;	
}

Open in new window

Comment
Watch Question
Web developer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE