Reputation:
I have to set image on the basis of fields value 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.
Upvotes: 2
Views: 838
Reputation: 9094
You can do this with a shorthand conditional.
<asp:Image ID="imgMyImage" runat="server" ImageUrl='<%# ((bool)Eval("Online")) ? "~/images/green.png" : "~/images/gray.png" %>' />
Upvotes: 4