How to display an image dynamically

Posted by Self-Innovator under ASP.NET on 12/18/2012 | Points: 10 | Views : 1769 | Status : [Member] | Replies : 1
Hi i wanted to display an image while html code generates in code behind in asp.net..Below i have provided my code please go throgh and rectify it...


System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
img.ImageUrl = "~/images/sample_seller.gif";
dt = ee.GetContactDetails(CustId);
StringBuilder sb = new StringBuilder();
if (dt.Rows.Count > 0)
{
sb.AppendLine("<html><body><center><table width='100%' cellspacing='0' border='1'");
sb.AppendLine("<tr>");
sb.AppendLine("<td colspan='4' width='100%' align='center' style='background-color: #FFAA2B;'>");
sb.AppendLine(img.ToString());
sb.AppendLine("</td>");
sb.AppendLine("</tr>");
sb.AppendLine("</table></center></body></html>");
}



in my output i am just getting as System.Web.UI.WebControls.Image instead of showing an image

Join Hands Change lives
Thanks & Regards
Straight Edge Society



Responses

Posted by: Jayakumars on: 3/18/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
//Try This Code Working
System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
img.ImageUrl = "~/images/addnew.png";
StringBuilder sb = new StringBuilder();
sb.AppendLine("<html><body><center><table width='100%' cellspacing='0' border='1'");
sb.AppendLine("<tr>");
sb.AppendLine("<td colspan='4' width='100%' align='center' style='background-color: #FFAA2B;'>");
sb.AppendLine("</td>");
sb.AppendLine("</tr>");
sb.AppendLine("</table></center></body></html>");
form1.Controls.Add (img);


Mark as Answer if its helpful to you

Self-Innovator, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response