Add an image dynamically

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.



Comments

Guest Author: Fernando27 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.



  • 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:
    Email: