如何在asp.net中的字符串生成器中绑定图像 [英] how to bind an image in string builder in asp.net

查看:76
本文介绍了如何在asp.net中的字符串生成器中绑定图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在字符串构建器中绑定图像。我会试试这个



string url =img / myimage.png;



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


Str.Append(< img src = + url + visible = ' true' runat =' server' 样式 =' width:75px; height:41px' < span class =code-attribute> / > );
Str.Append(< / td > );







但它没有显示任何图像。

帮我解决这个问题

解决方案

你忘了在引号之间加上URL。

一个更好的解决方案将是:

 Str.Append( < img src =' + url +  'visible ='true'runat ='server'style = '宽度:75px;高度:41px'/>); 





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



请注意使用双引号内的单引号引号分隔字符串。


检查页面的来源以确保< img>标签就在那里,检查网络工具以查看浏览器是否尝试下载图像。如果它有,结果是404那么你的url路径是错误的。尝试使用绝对路径而不是相对路径;



 url =/ img / myimage.png;  



最后没有必要添加runat = server,因为这对于以纯文本形式注入响应流的html不起作用。


我得到了输出这个



 Str.Append(<   td     class   ='  style2'    rowspan   ='  2' > ); 
string imgurl =〜/ img / images.png;
Str.AppendFormat(< img id = \ SpeIma \ u = \ image \ src = \ {0} \ 样式 =' width:75px; height:41px' / > , RESOLVEURL(imgUrl的));
Str.Append(< / tr > );


how to bind image in string builder. i will try with this

string url="img/myimage.png";

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

解决方案

You forgot to enclose the URL between quotes.
A better solution would be:

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


or

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.


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.


i got output by using This

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>");


这篇关于如何在asp.net中的字符串生成器中绑定图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆