Resources » Code Snippets » Images

Add an image dynamically

Updated: Category: Images
Author: Member Level: SilverPoints: 7

You can add an image dynamically with code below. using this ypu can also crate td(table cell) dymaically and add to the tr. for that you have to give the id for tr and set the property for runatserver=true.

int tdcount = 0;
//get the count of table cells in tr
tdcount = tr1.Controls.Count;
//Create a new table cell
HtmlTableCell tdcell = new HtmlTableCell();
//Create a new image control
Image img = new Image();
//set the url for image
img.ImageUrl = "C:\img.jpg";
img.Width = 120; //set the image width
img.Height = 100; //set the image hight
tdcell.ColSpan = 3; //set the colspan for table cell
tdcell.RowSpan = 4; //set the rowspan for table cell
tdcell.Controls.Add(img); // place image in table cell
tr1.Controls.AddAt(tdcount, tdcell); // Add table cell to the table row.

Did you like this resource? Share it with your friends and show your love!

Responses to "Add an image dynamically"
Guest Author: Fernando   27 Jan 2012
Very Good, but I did it and no success.
I tried put a image in all cells dinamically.
And just one image is showed. And in the last cell of my table.


Post Comment:

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)

    Type the numbers and letters shown on the left.

    Submit Article     Return to Article Index
    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India