如何在源页面中声明条件 [英] How to declare if condition in source page

查看:61
本文介绍了如何在源页面中声明条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

Here is my code:

<% if (Eval(art_avatar_url) != "")
            {%>
                <img alt="<%#Eval("name")%>" title="<%#Eval("name")%>" src='../img/avatars/<%#Eval("img_url")%>' style="width: 80px; height: 80px">
            <%}
              else
              {%>
                <img alt="<%#Eval("name")%>" title="<%#Eval("name")%>" src="../img/blank.gif" style="width: 80px; height: 80px">
            <%}%>



在此代码中,if条件中的错误.我知道这不是在Eval函数中声明条件的正确格式.
请帮我声明一下.

在此先感谢

如何在后面的代码中执行此操作?

请帮助我如何在后面声明代码以及如何在源页面中调用


请参阅我弄错的代码:



in this code the error in if condition. I know this is not a correct format to declare if condition in Eval function.
Please help me how to declare this.

Thanks in advance

How to do this in code behind?

please help me how to declare code behind and how to call in source page


See the code where i get wrong:

<img alt="<%#Eval("name")%>" title="<%#Eval("name")%>"

                        src='<%#Eval("avatar_url") != "" ? "../img/avatars/"+ Eval("avatar_url") : "../img/blank.gif"%>'

                            style="width: 80px; height: 80px">

推荐答案

这很丑陋您应该在后面的代码中执行此操作,以使代码易于阅读.只需设置文字并设置其属性,甚至设置asp:Image.
This is ugly has hell. You should do this in your code behind, so your code is readable. Just set up a literal and set it''s properties, or even an asp:Image.


尝试这种方式,它将起作用

Try that way, it will work

<img alt="<%#Eval("name")%>" title="<%#Eval("name")%>"
                        src=''<%#Eval("art_avatar_url") != "" ? "images/"+ Eval("img_url") : "images/blank.gif"%>''
                            style="width: 80px; height: 80px">



在下面尝试此代码

Try this code below
<img alt='<%#Eval("name")%>' title='<%#Eval("name")%>'

src='<%# string.IsNullOrEmpty(Eval("art_avatar_url").ToString())?"images/blank.gif":"images/"+ Eval("img_url").ToString() %>'

style="width: 80px; height: 80px">


希望这能解决您的问题.


Hope this will address your issue.


这篇关于如何在源页面中声明条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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