Click here to Skip to main content
15,890,436 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to bind image in string builder. i will try with this

string url="img/myimage.png";

XML
Str.Append("<td class='style2' rowspan='2'>");


      Str.Append("<img src="+url+" visible='true' runat='server' style='width: 75px; height: 41px' />");
   Str.Append("</td>");



but it does not show any image.
help me how to solve this
Posted
Updated 5-Apr-22 23:14pm
v2

You forgot to enclose the URL between quotes.
A better solution would be:
C#
Str.Append("<img src='" + url + "' visible='true' runat='server' style='width: 75px; height: 41px' />");

or
C#
Str.AppendFormat("<img src='{0}' visible='true' runat='server' style='width: 75px; height: 41px' />", url);

Kindly note the use of the single quotes inside the double-quotes-delimited-string.
 
Share this answer
 
v2
Comments
Rams@music 26-Oct-15 5:13am    
thanks for reply.
i try with these two but same result image is not displayed
Check the source of the page to make sure the <img> tag is there, check the network tools to see if the browser has attempted to download the image. If it has and the result is 404 then your url path is wrong. Try using an absolute path rather than a relative one;

url = "/img/myimage.png";


Finally there is no point adding runat=server as that won't work for html you are injecting into the response stream as plain-text.
 
Share this answer
 
Comments
Rams@music 26-Oct-15 5:23am    
hi thanks for reply.
my image url path is correct. iam use this one in design page it showing the image. but when i try this one with backend with string builder it not show the image. how can i solve
F-ES Sitecore 26-Oct-15 5:34am    
You haven't supplied enough code to be able to give specific help. View the source of the page and find your tag. Work out what is wrong with it and fix it. If the tag doesn't appear at all you need to look at the code that adds it, if it appears but is malformed you need to fix the code that renders the tag. If the tag is fine but the url is wrong you need to use the right url. We can't access your machine or run your code in context.
Rams@music 26-Oct-15 5:44am    
thanks i got output.
i got output by using This

XML
Str.Append("<td class='style2' rowspan='2'>");
              string imgurl = "~/img/images.png";
              Str.AppendFormat("<img id=\"SpeIma\" u=\"image\" src=\"{0}\" style='width: 75px; height: 41px' />", ResolveUrl(imgurl));
              Str.Append("</tr>");
 
Share this answer
 
Str.Append("");
string imgurl = "~/img/images.png";
Str.AppendFormat("", ResolveUrl(imgurl));
Str.Append("");
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900