Hiding content in a transformation

Ben Kay asked on April 12, 2016 19:24

I have a transformation and I sometimes need to hide an EventSchedule link from the page if there is not one available.

<a class="panel panel-default" >Sample Itinerary - <%# Eval("EventSchedule") %> </a>

How could I approach this?

  1. Add a boolean to the page type called ShowEventSchedule and only render this link if it is checked
  2. Can I detect if EventSchedule is empty and only render the HTML if it is not

Correct Answer

Laura Frese answered on April 12, 2016 19:41

If you decide to add a boolean to the page type you can use the IfTrue Transformation Method
<%# IfTrue(Eval("EventSchedule"), "", "<a href='mylink'>Schedule</a>") %>

And as Zacahry mentioned you can use IfEmpty similarly

<%# IfEmpty(Eval("EventSchedule"),"","<a href='mylink'>"+Eval("EventSchedule")+"</a>") %>
Or.. I dont know how you are using that field.. if it is your link.... <%# IfEmpty(Eval("EventSchedule"),"","<a href="+Eval("EventSchedule")+">Schedule</a>") %>

2 votesVote for this answer Unmark Correct answer

Recent Answers


Zach Perry answered on April 12, 2016 19:29

You can use <%# IfEmpty(Eval("EventSchedule"),"Empty","Not Empty") %>

0 votesVote for this answer Mark as a Correct answer

Anton Grekhovodov answered on April 12, 2016 20:32

Another way to show the link:

<asp:PlaceHolder runat="server" Visible="<%# Eval("EventSchedule") != null %>">
<a class="panel panel-default" >Sample Itinerary - <%# Eval("EventSchedule") %> </a>
</asp:PlaceHolder>
4 votesVote for this answer Mark as a Correct answer

Ben Kay answered on April 12, 2016 20:44

Thanks - this was the final code that worked

<%# IfEmpty(Eval("EventSchedule"),"","<div class='col-sm-12'><a data-target='#dvShedule' class='panel panel-default' data-toggle='collapse' aria-expanded='true'><div class='borderBox'><p class='spaceBetweenLines leftTextMargin'>Sample Itinerary<span class='glyphicon glyphicon-plus' style='float:right'></span></p></div></a><div id='dvShedule' class='collapse'> <p>" + Eval("EventSchedule").ToString() +"</p> </div>") %>
1 votesVote for this answer Mark as a Correct answer

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