How do I conditionally control the visibility of a control in ASP.NET?

后端 未结 1 1182
没有蜡笔的小新
没有蜡笔的小新 2021-01-19 05:26

I\'ve got an asp:Image. I want this control to display, only if <%#Eval(\"Image\")%> is not null.

I do not know how to write this con

相关标签:
1条回答
  • 2021-01-19 05:48

    You can bind the Visible property of your control to the expression and call DataBind() while the page is loading:

    <asp:Image runat="server" id="image" Visible='<%#Eval("Image") != null %>' />
    

    If you are not using server controls and want to show/hide simple markup, you can simply enclose it in an if statement:

    <% if ( condition ) { %>
        <img src='<%= linkToImageSource %>' />
    <% } %>
    
    0 讨论(0)
提交回复
热议问题