我正在使用中继器在新闻部分显示新闻.在我的新闻部分,我有2个标签(标题,说明)和一个图像字段.下面是我用来填充中继器的代码:
<asp:Repeater ID="rptNews" runat="server"> <ItemTemplate> <asp:Image ID="newsImage" runat="server" ImageUrl='<%#String.format("../Images/News/{0}",Eval("newsImage")) %>' /> <asp:Label ID="newsTitle" runat="server" Text='<%#Eval("newsTitle") %>'></asp:Label> <br /> <asp:Label ID="newsDescription" runat="server" Text='<%#Eval("newsDescription") %>'></asp:Label> <br /> <div class="clear"> </div> </ItemTemplate> </asp:Repeater>
我想使用if语句,例如,如果Eval(“newsImage”)为null,那么我想禁用图像控件,并显示新闻的标题和描述.关于如何实现这一点的任何建议.
解决方法
应该是… Visible =’<%#Eval(“newsImage”)ToString()!=“Null”%>‘
<asp:Image ID="newsImage" runat="server" Visible='<%# Eval("newsImage").ToString() == "Null" %>' ImageUrl='<%#String.Format("../Images/News/{0}",Eval("newsImage")) %>' />
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。