Click here to Skip to main content
11,644,286 members (67,713 online)
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 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
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  

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

  Print Answers RSS
0 OriginalGriff 610
1 jyo.net 484
2 Afzaal Ahmad Zeeshan 453
3 Sergey Alexandrovich Kryukov 369
4 CPallini 352
0 OriginalGriff 925
1 DamithSL 636
2 Afzaal Ahmad Zeeshan 622
3 Sergey Alexandrovich Kryukov 548
4 CPallini 521


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100