如果条件在转发器内 [英] if condition inside repeater

查看:64
本文介绍了如果条件在转发器内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好所有

i有一个场景,我使用转发器从数据库显示前5个新闻项目

每个新闻项目都有以下字段:

新闻ID

新闻瓷砖

新闻机构

新闻图片路径(新闻图片的路径)是可选的(可以为空)



我的问题是:只有当该项目的图像路径不为空时,如何让转发器显示新闻项目的图像?



下面是我的转发器的itemTemplate部分的片段:

hello all
i have a scenario where i display top 5 news items from a database using a repeater
each news item has the following fields:
news ID
News tile
News Body
News Image path (path to news image) that is optional (can be null)

My question is: how to get the repeater to display an image for a news item only if the image path for that item is not null??

Below is a snippet of the itemTemplate section of my repeater:

<ItemTemplate>

                    <h3>
                        <asp:Image ID="Image1" ImageUrl="<%#Item.NewsImagePath %>" Width="75" Height="75" runat="server" />
                        <%#Item.NewsTitle %>

                    </h3>
                    <div>

                        <%#Item.NewsBody %>
                    </div>
                </ItemTemplate>







非常感谢:)




Many thanks :)

推荐答案

试试这个

Try this
<asp:image id="Image1" imageurl="<%#Item.NewsImagePath %>" 
 Visible ='<%# bool.Parse(Eval("NewsImagePath") == null) %>' Width="75" Height="75" runat="server" /></asp:image>


nope,编译错误

i相信eval应该在< %%>中。话虽如此,我无法弄清楚如何完成它< %%>已经被使用了

谢谢你的帮助

:)
nope, compilation error
i believe the eval should be in <% %>. that being said, i cant figure out how to accomplish it as <% %> is already being used
thanks for your help
:)


我刚刚在第一个解决方案的帮助下解决了它/>
图像标记将是:

I just solved it with the help of the first solution
the image tag will be :
<asp:image id="Image1" imageurl="<%#Item.NewsImagePath %>"

 Visible ='<%# Item.NewsImagePath!=null %>' Width="75" Height="75" runat="server" />





谢谢所有



thanks all


这篇关于如果条件在转发器内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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