找不到EVAL文件名时替换img [英] substitute img when EVAL file name is not found

查看:51
本文介绍了找不到EVAL文件名时替换img的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有一种简单的方法可以做到这一点。如果文件丢失,我需要在一个asp图像对象中显示一个虚拟图像。这是我的asp.net 2.0标记:


< asp:Image ID =" imgGrad" RUNAT = QUOT;服务器" BorderColor =" DimGray"

BorderStyle =" Solid"边框宽度= QUOT; 1px的"高度= QUOT; 120像素" ImageUrl =''<%#

"〜/ Images / ClassmatePics /" &安培; Eval(GradPhotoFileName)%>''ToolTip ="点击确定

enlarge" />< / td>

" GradPhotoFileName"存储在表中的字段中。如果表中存储的文件名

是JeffJones.jpg。但是没有JeffJones.jpg文件在

"〜/ Images / ClassmatePics /"文件夹然后我有一个我想要的虚拟jpg图像

来显示(MissingPhoto.jpg)。


我希望有''这可能是一个简单的方法,可能在EVAL代码,但我不知道
知道如何。有人可以帮帮我吗?


谢谢,


基思

解决方案

可能最简单的方法是调用一个接受类型

对象的受保护方法(例如,Eval(GradPhotoFileName)) - 并返回正确的字符串

url到图像,或替代图像网址。

- 彼得

" Keith G Hicks" < kr*@comcast.netwrote in message

news:eZ ************** @ TK2MSFTNGP05.phx.gbl ...


我希望有一个简单的方法来做到这一点。如果文件丢失,我需要在一个asp图像对象中显示一个虚拟图像



。这是我的asp.net 2.0标记:


< asp:Image ID =" imgGrad" RUNAT = QUOT;服务器" BorderColor =" DimGray"

BorderStyle =" Solid"边框宽度= QUOT; 1px的"高度= QUOT; 120像素" ImageUrl =''<%#

"〜/ Images / ClassmatePics /" &安培; Eval(GradPhotoFileName)%>''ToolTip ="点击



enlarge" />< / td>


" GradPhotoFileName"存储在表中的字段中。如果表中存储的文件名



是JeffJones.jpg但是没有JeffJones.jpg提交



"〜/ Images / ClassmatePics /"文件夹然后我有一个我想要的虚拟jpg图像

来显示(MissingPhoto.jpg)。


我希望有''这可能是一个简单的方法,可能在EVAL代码,但我

不要

知道如何。有人可以帮帮我吗?


谢谢,


基思


我很欣赏这个提示,但对于所有这些(asp.net)来说都是新手我已经

不知道如何去做。我很好用VB并且可以创建sub和

函数就好了如果这就是你的意思我可以做那个部分我想

但是实现它在我的标记下面对我来说并不是很清楚。我需要尽可能多的帮助。


谢谢,


基思

Peter Bromberg [C#MVP]" < pb ******* @ nospammaam.yahoo.com在留言中写道

新闻:30 ********************* ************* @ microsof t.com ...


可能最简单的方法是调用接受类型的受保护方法

object(例如,Eval(" GradPhotoFileName")) - 并返回正确的



string


url到图像,或替代图像网址。

- 彼得

" Keith G Hicks" < kr*@comcast.netwrote in message

news:eZ ************** @ TK2MSFTNGP05.phx.gbl ...


我希望有一个简单的方法来做到这一点。如果文件丢失,我需要在一个asp图像对象中显示一个虚拟图像



。这是我的asp.net 2.0



加价:



< asp:Image ID =" imgGrad" RUNAT = QUOT;服务器" BorderColor =" DimGray"

BorderStyle =" Solid"边框宽度= QUOT; 1px的"高度= QUOT; 120像素" ImageUrl =''<%#

"〜/ Images / ClassmatePics /" &安培; Eval(GradPhotoFileName)%>''ToolTip ="点击



enlarge" />< / td>

" GradPhotoFileName"存储在表中的字段中。如果表中存储的文件名



是JeffJones.jpg但是没有JeffJones.jpg提交



"〜/ Images / ClassmatePics /"文件夹然后我有一个虚拟jpg图像,我



想要


显示(MissingPhoto.jpg)。


我希望有一个简单的方法可以在EVAL代码中做到这一点,但我

不要

知道怎么做。有人可以帮帮我吗?


谢谢,


基思



从代码隐藏中执行此操作。你有GradPhotoFileName的值,你

可以检查System.Io.File.Exists(),如果它没有,设置.ImageUrl

imgGrad图像的属性到您的虚拟图像URL。我不知道如何将你的图像绑定到数据上,但是如何在代码隐藏中分配值

将取决于你的方法重新使用。


-

------------------------- --------------------------

SM Altaf [MVP]
http://www.mendhak.com/

" Keith G Hicks" < kr*@comcast.net写信息

新闻:#m ************** @ TK2MSFTNGP04.phx.gbl ...
< blockquote class =post_quotes>
我很欣赏这个提示,但是对于所有这些(asp.net)都是新手我已经

不知道如何去做。我很好用VB并且可以创建sub



函数就好了所以如果这就是你的意思我可以做那个部分我想

但是在我的标记中实现它对我来说并不是很清楚。我需要尽可能多的帮助。


谢谢,


基思

Peter Bromberg [C#MVP]" < pb ******* @ nospammaam.yahoo.com写在

留言

news:30 ************* ********************* @ microsof t.com ...


>可能是最简单的方法是调用接受类型
对象的受保护方法(例如,Eval(GradPhotoFileName)) - 并返回正确的



string


>图片的url,或备用图片网址。
- Peter
Keith G Hicks < kr*@comcast.netwrote in message
新闻:eZ ************** @ TK2MSFTNGP05.phx.gbl ...


我希望有一个简单的方法来做到这一点。我需要在一个asp图像对象中显示一个假的

图像

如果文件丢失了。这是我的asp.net 2.0



加价:


>

< asp:Image ID =" imgGrad" RUNAT = QUOT;服务器" BorderColor =" DimGray"

BorderStyle =" Solid"边框宽度= QUOT; 1px的"高度= QUOT; 120像素" ImageUrl =''<%#

"〜/ Images / ClassmatePics /" &安培; Eval(GradPhotoFileName)%>''

ToolTip ="点击



enlarge" />< / td>


" GradPhotoFileName"存储在表中的字段中。如果表中存储的文件名



是JeffJones.jpg但是没有JeffJones.jpg提交



"〜/ Images / ClassmatePics /"文件夹然后我有一个虚拟jpg图像,我



想要


显示(MissingPhoto.jpg)。


我希望有一个简单的方法可以在EVAL代码中做到这一点,但我

不要

知道怎么做。有人可以帮帮我吗?


谢谢,


基思



I''m hoping there''s a simple way to do this. I need to show a dummy image in
an asp image object if the file is missing. Here''s my asp.net 2.0 markup:

<asp:Image ID="imgGrad" runat="server" BorderColor="DimGray"
BorderStyle="Solid" BorderWidth="1px" Height="120px" ImageUrl=''<%#
"~/Images/ClassmatePics/" & Eval("GradPhotoFileName") %>'' ToolTip="Click to
enlarge" /></td>
"GradPhotoFileName" is stored in a field in a table. If the file name stored
in the table is "JeffJones.jpg" but there is no "JeffJones.jpg" file in the
"~/Images/ClassmatePics/" folder then I have a dummy jpg image that I want
to show ("MissingPhoto.jpg").

I''m hoping there''s an easy way to do that maybe in the EVAL code but I don''t
know how. Can someone help me out?

Thanks,

Keith

解决方案

Probably the easiest way is to call a protected method that accepts type
object (e.g., Eval("GradPhotoFileName") ) -- and returns the proper string
url to the image, or the alternate image url.
--Peter
"Keith G Hicks" <kr*@comcast.netwrote in message
news:eZ**************@TK2MSFTNGP05.phx.gbl...

I''m hoping there''s a simple way to do this. I need to show a dummy image
in
an asp image object if the file is missing. Here''s my asp.net 2.0 markup:

<asp:Image ID="imgGrad" runat="server" BorderColor="DimGray"
BorderStyle="Solid" BorderWidth="1px" Height="120px" ImageUrl=''<%#
"~/Images/ClassmatePics/" & Eval("GradPhotoFileName") %>'' ToolTip="Click
to
enlarge" /></td>
"GradPhotoFileName" is stored in a field in a table. If the file name
stored
in the table is "JeffJones.jpg" but there is no "JeffJones.jpg" file in
the
"~/Images/ClassmatePics/" folder then I have a dummy jpg image that I want
to show ("MissingPhoto.jpg").

I''m hoping there''s an easy way to do that maybe in the EVAL code but I
don''t
know how. Can someone help me out?

Thanks,

Keith


I appreciate the hint but being pretty new to all of this (asp.net) I have
no idea how to go about doing that. I''m fine with VB and can create subs and
functions just fine so if that''s what you mean I can do that part I guess
but implementing it in my markup below is not remotely clear to me. I need
as much help as possible.

THanks,

Keith

"Peter Bromberg [C# MVP]" <pb*******@nospammaam.yahoo.comwrote in message
news:30**********************************@microsof t.com...

Probably the easiest way is to call a protected method that accepts type
object (e.g., Eval("GradPhotoFileName") ) -- and returns the proper

string

url to the image, or the alternate image url.
--Peter
"Keith G Hicks" <kr*@comcast.netwrote in message
news:eZ**************@TK2MSFTNGP05.phx.gbl...

I''m hoping there''s a simple way to do this. I need to show a dummy image
in
an asp image object if the file is missing. Here''s my asp.net 2.0

markup:


<asp:Image ID="imgGrad" runat="server" BorderColor="DimGray"
BorderStyle="Solid" BorderWidth="1px" Height="120px" ImageUrl=''<%#
"~/Images/ClassmatePics/" & Eval("GradPhotoFileName") %>'' ToolTip="Click
to
enlarge" /></td>
"GradPhotoFileName" is stored in a field in a table. If the file name
stored
in the table is "JeffJones.jpg" but there is no "JeffJones.jpg" file in
the
"~/Images/ClassmatePics/" folder then I have a dummy jpg image that I

want

to show ("MissingPhoto.jpg").

I''m hoping there''s an easy way to do that maybe in the EVAL code but I
don''t
know how. Can someone help me out?

Thanks,

Keith



Do this from the codebehind. You have the value of "GradPhotoFileName", you
can check if System.Io.File.Exists() and if it doesn''t, set the .ImageUrl
property of your imgGrad image to your dummy image URL. I do not know how
you''re binding your image to the data though, but how you assign the values
in the codebehind will depend on the method you''re using.

--
---------------------------------------------------
S.M. Altaf [MVP]
http://www.mendhak.com/
"Keith G Hicks" <kr*@comcast.netwrote in message
news:#m**************@TK2MSFTNGP04.phx.gbl...

I appreciate the hint but being pretty new to all of this (asp.net) I have
no idea how to go about doing that. I''m fine with VB and can create subs
and
functions just fine so if that''s what you mean I can do that part I guess
but implementing it in my markup below is not remotely clear to me. I need
as much help as possible.

THanks,

Keith

"Peter Bromberg [C# MVP]" <pb*******@nospammaam.yahoo.comwrote in
message
news:30**********************************@microsof t.com...

>Probably the easiest way is to call a protected method that accepts type
object (e.g., Eval("GradPhotoFileName") ) -- and returns the proper

string

>url to the image, or the alternate image url.
--Peter
"Keith G Hicks" <kr*@comcast.netwrote in message
news:eZ**************@TK2MSFTNGP05.phx.gbl...

I''m hoping there''s a simple way to do this. I need to show a dummy
image
in
an asp image object if the file is missing. Here''s my asp.net 2.0

markup:

>
<asp:Image ID="imgGrad" runat="server" BorderColor="DimGray"
BorderStyle="Solid" BorderWidth="1px" Height="120px" ImageUrl=''<%#
"~/Images/ClassmatePics/" & Eval("GradPhotoFileName") %>''
ToolTip="Click
to
enlarge" /></td>
"GradPhotoFileName" is stored in a field in a table. If the file name
stored
in the table is "JeffJones.jpg" but there is no "JeffJones.jpg" file in
the
"~/Images/ClassmatePics/" folder then I have a dummy jpg image that I

want

to show ("MissingPhoto.jpg").

I''m hoping there''s an easy way to do that maybe in the EVAL code but I
don''t
know how. Can someone help me out?

Thanks,

Keith



这篇关于找不到EVAL文件名时替换img的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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