开发者

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" %>' />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜