If Else condition in transformation

Jeewani Jayasuriya asked on October 7, 2021 10:57

Hi,

Please can someone help me how to re-direct if the "file description" is NOT empty.

<a href="<%# Eval("FileDescription") %>" >
<img src="<%# GetFileUrl("FileAttachment") %>" alt="<%# Eval("FileName") %>" style="width: 100%; " class="img-responsive" >

If file description is empty I want to add below line

<img src="<%# GetFileUrl("FileAttachment") %>" style="width: 100%; height: 100%; " class="img-responsive" >

Below is my full code.

Thank you!

Recent Answers


David te Kloese answered on October 7, 2021 12:38

Since you're using ASCX type best would be to use the ASP placeholder way.

Somthing like you can see below. The 'your code' part only gets rendered when FileDescription equals the empty string.

<asp:PlaceHolder ID="ph1" runat="server" Visible='<%# Eval("FileDescription").ToString().Equals("") %>'>
// your code
</asp:PlaceHolder>
0 votesVote for this answer Mark as a Correct answer

Jeewani Jayasuriya answered on October 7, 2021 12:43

Thanks David. I am not using ASCX. Is there another way of doing this?

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on October 7, 2021 13:00

so your using text xml tranformaiton type?

as your examples don't work in this either.

in for the XML transformations you'll need something like:

{%
    if (String.IsNullOrEmpty(FileDescription) {
    ...
    }
    else {
    ...
    }
%}
1 votesVote for this answer Mark as a Correct answer

theenesraja sivaraja answered on October 8, 2021 07:39

Have you explored the Reference - Transformation methods that Kentico has. I think you should be able to use the IfEmpty method to achieve what you want.

E.g. <%# IfEmpty(Eval("FileDescription"), "Description Empty", Eval("FileDescription")) %>

0 votesVote for this answer Mark as a Correct answer

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