1

I have two images progress.png and completed.png. Depending on the status in the db table (In Progress of Complete), I want to display the appropriate image. What is the correct syntax for the IIF() statement within asp.net? Thanks for your help.

pseudocode:

<asp:image ImageUrl='<%# IIF(Eval("Status").Equals("In Progress")
display - 'images/progress.png') 
else if status equals "Complete"
display - 'images/complete.png' %>' />

2 Answers 2

2

I know this will not answer your question regarding the IIF syntax, but will solve your problem regarding displaying the image.

I would rather use this:

<asp:image ImageUrl='<%# GetStatusImage(Eval("Status").ToString()) %>' />

and write the following method in your code-behind.

public string GetStatusImage(string status)
{
     switch(status)
         case "In Progress":
             return "images/progress.png";
         break;
         case "Complete":
             return "images/complete.png";
         break;
         case default:
             return string.Empty;
         break;        
}
Sign up to request clarification or add additional context in comments.

Comments

0

The best thing to do is create a public method that would return the right image and the call the method from code like this:

<%= GetProgressImage() %>

Alternatively, this might work if you have only two states:

<%= Eval("Status").Equals("Complete") ? "'images/complete.png'"  : "'images/progress.png'"   %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.