Using If Else in HTML page inside <%# %>tags
I have to set image on the basis of fields valu开发者_StackOverflowe coming from db. I want it to achieve via. tags <%# %>. For example i have collection binded with grid. It has a Field called Online which is boolean. So if the value of Online is true then the green.png will be set as path of asp:image control else grey.png will be the path of the asp: image control.
You can do this with a shorthand conditional.
<asp:Image ID="imgMyImage" runat="server" ImageUrl='<%# ((bool)Eval("Online")) ? "~/images/green.png" : "~/images/gray.png" %>' />
精彩评论