Transformation - if empty, omit

L Younkins asked on April 15, 2021 17:46

I have a transformation with a url link that is working, but need to hide the field, if empty.

Code
<div><p><strong>View <a href="<%# Eval("CatalogURL") %>" target="_blank"> Pathway for this Program</a>.</strong></p></div>

If there is no catalog link, how can I hide this? Should I use a String.IsNullOrEmpty? If so, exactly how do I write it as a url link?

Correct Answer

Liam Goldfinch answered on April 15, 2021 22:31

I would recommend looking up the Transformation Methods available on the documentation here.

You will probably want to do something like:

<%# IfEmpty(Eval("CatalogURL"), "", string.Format("<div><p><strong>View <a href=\"{0}\" target=\"_blank\"> Pathway for this Program</a>.</strong></p></div>", Eval("CatalogURL"))) %>
1 votesVote for this answer Unmark Correct answer

Recent Answers


L Younkins answered on April 26, 2021 21:04

This didnt work for me. It just hid the field completely, even those not empty. I only want to hide it for the field is empty.

0 votesVote for this answer Mark as a Correct answer

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