Transformations Questions

Joshua Lewis asked on March 26, 2015 15:49


I'm editing a transformation and I want to use the IfEmpty method.

All I want to do is basically:

<%# IfEmpty(Eval("URL"), "NA", <a href="Eval("URL")">Register now)) %>

I've tried the HTML code with and without quotes around it and I get an error "error CS1026: ) expected" with quotes and the ")" switched with a ">" for without quotes.

Is there a special way to get it to take HTML code or is there a better way to write this method?

thank you!

Correct Answer

Brenden Kehren answered on March 26, 2015 16:02

You're escaping your string by using double quotes. Around your HREF use single quotes.

<%# IfEmpty(Eval("URL"), "NA", <a href='Eval("URL")'>Register now)) %>
2 votesVote for this answer Unmark Correct answer

Recent Answers

Juraj Ondrus answered on March 26, 2015 16:04


Or, this sample works as well:

<%# IfEmpty(Eval("FileAttachment"), "no image", "<img alt=\"" + Eval("FileName") + "\" src=\"" + GetFileUrl("FileAttachment") + "?maxsidesize=180\" border=\"0\" />") %>

So, you need to put it into double quotes and then escape the inner ones.

1 votesVote for this answer Mark as a Correct answer

Joshua Lewis answered on March 26, 2015 16:06

both great suggestions. Thank you all. I had an itching feeling there was a double quote/single quote problem I was overlooking.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.