如何动态地将图像分配给图像不在应用程序根目录上的图像按钮 [英] How do I dynamically assign images to image buttons where images are not on the application root

查看:101
本文介绍了如何动态地将图像分配给图像不在应用程序根目录上的图像按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我试图在运行时将图像分配给图像按钮,但是当我运行我的应用程序时,我只得到x。如果我做了类似



 img_header.ImageUrl =〜/ images /& imagefilename& .jpg





但是,如果我尝试像



 img_header.ImageUrl =C:\ Files\Images\imagefilename.jpg





然后它不会在运行时加载图像。



当我在设计时设置ImageUrl时,它会在运行时显示图像。但是这对我不起作用,因为我需要在运行时根据不同的因素更改图像



任何帮助都将受到赞赏

解决方案

请参阅我对该问题的评论。以下是您应该使用的内容:

http ://msdn.microsoft.com/en-us/library/ms524632%28v=vs.90%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.web .httpserverutility.mappath%28v = vs.110%29.aspx [ ^ ]。



-SA

Hi all,
I am trying to assign images during runtime to an image button but I am only getting "x" when i run my application. It works if i do something like

img_header.ImageUrl = "~/images/" & imagefilename & ".jpg"



However, if I try something like

img_header.ImageUrl = "C:\Files\Images\imagefilename.jpg"



then it doesn't load the image during runtime.

When I set the ImageUrl during design time, then it shows the image at runtime. but this doesn't work for me because i need to change the image during runtime based on different factors

Any help would be appreciated

解决方案

Please see my comments to the question. Here is what you should use:
http://msdn.microsoft.com/en-us/library/ms524632%28v=vs.90%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath%28v=vs.110%29.aspx[^].

—SA


这篇关于如何动态地将图像分配给图像不在应用程序根目录上的图像按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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