Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 2-Feb-13 23:14pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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("

"));
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 279
1 Maciej Los 168
2 George Jonsson 154
3 Sarvesh Kumar Gupta 130
4 Dave Kreskowiak 130


Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 28 May 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid