Click here to Skip to main content
14,734,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to everyone. I am working on a website and I want to create a gallry page. So according to the number of images, the gallry will be updated automatically if I can do the following.

The images are being added to database with an UploadImage page. So I have all my images in my database with their tooltips, categories, and imageurls. The in the .cs fuke I want to create a dynamic array of ImageButtons with their all features, e.g. ImageUrl, Tooltip, OnClientClick, etc.

If anyone helps me I will appreciate that. Thanks anyway. The sooner comes the answer, it gets better.
Posted

Hi Cengiz,

Here's a basic example for dynamic creation of an ImageButton using Code-Behind:
private void RenderImageButtons()
{
    ImageButton img = new ImageButton();
    img.ID = "img";
    img.AlternateText = "ImageButton";
    //img.Click += new ImageClickEventHandler(img_Click);
    img.Command +=new CommandEventHandler(img_Command);
    img.CommandName = "select";
    img.CommandArgument = "~/ConcertTickets.aspx";
    img.Width = Unit.Percentage(100.00);
    this.Page.Controls.Add(img);
}


You can handle an array of course, give each ImageButton it's ID so that you can then access it and relate to it, or handle it's properties etc.


Cheers,
Edo
   
v2
ImageButton[] image = new ImageButton[25];
for (int i = 0; i < 5; i++)
{
image[i] = new ImageButton();
image[i].Height = 100;
image[i].Width = 75;
image[i].BorderWidth = 0;
image[i].ImageUrl = "~/Images/Danger.png";
image[i].Visible = true;
form1.Controls.Add(image[i]);
form1.Controls.Add(new LiteralControl("

"));
}
   

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