Click here to Skip to main content
15,921,716 members
Please Sign up or sign in to vote.
1.22/5 (5 votes)
See more:
Hello !

I'm trying to put images in my ContentPlaceHolder but I don't know how to do that with c# code
Posted
Updated 3-Aug-22 22:21pm
Comments
Nirav Prabtani 3-Jun-14 14:31pm    
why don't you use Repeater ,datalist or gridview for displaying images??

You can use this code to bind image(s) to your Content place holder. If you want more than one image then put it in a loop.
You can assign Image URL by many ways. I have shown some ways. Hope it is useful to you.

C#
protected void btnImportImages_Click(object sender, EventArgs e)
        {
            Image im = new Image();
            im.ID = "image";
            im.ImageUrl = "~/Image.JPG/";

            //alternatives for giving path ☺
            //im.ImageUrl=(@"C:\Image.JPG");
            //im.ImageUrl = Server.MapPath("~/Imagepath/ImageName.jpg");
            PlaceHolder1.Controls.Add(im);

        }
 
Share this answer
 

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