I've had a look through the questions on here, but none seem to answer my question.
I have a ASP.NET repeater grid that is set up to bound to a list that shows what the value of that item is. At the moment, it just shows the text value of the variable i.e. OFF, but what I want it to do is display the appropriate image i.e. if its off, show green image, if its on, show red image.
This is what I'm trying to do in the code, presumed you did it here instead of the aspx.cs?
<td><%# DataBinder.Eval(Container.DataItem, "Spill") == "OFF" ? %>
<asp:Image runat="server" ImageUrl="~/Images/green.JPG" />
<%:%>
<asp:Image runat="server" ImageUrl="~/Images/red.JPG" /> %>
</td>
The compiler is complaining about the '%>' after the ? and the '%>' after the : so obviously I haven't got it right, but can't think how else to do it.
Thanks for anyones help in advance
Markup:
<asp:Image runat="server"
ImageUrl='<%# WhichImage(DataBinder.Eval(Container.DataItem, "Spill")) %>' />
Code-behind:
protected string WhichImage(object spill)
{
string result = "~/Images/green.JPG";
string spillResult= (string)spill;
if(!spillResult.Equals("OFF"))
{
result = "~/Images/red.JPG";
}
return result;
}