Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Help me please (Transformation) View modes: 
User avatar
Member
Member
zhaojicheng-artmtech - 4/27/2009 11:24:52 AM
   
Help me please (Transformation)
Can I use conditional statements in transformation like this

<% If #DataBinder.Eval(Container.DataItem,"StatusID") = 1 then %>
...
<% End If%>

if not what should i do.
thanks

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 4/28/2009 5:56:07 AM
   
RE:Help me please (Transformation)
Hi,

you could use the IfCompare function. Please see our API Reference:

http://devnet.kentico.com/downloads/kenticocms_api.zip

CMS.Controls ► CMSAbstractTransformation ► IfCompare(Object, Object, Object, Object)

Best regards,
Helena Grulichova


User avatar
Member
Member
rebecca.wells - 7/14/2009 1:18:18 PM
   
RE:Help me please (Transformation)
I tried to use the IfCompare but I am getting an error. Here is the code snippet:

<%# IfCompare(Eval("HolidayHoursActive"),"True","","<tr><td><strong>Holiday Hours:</strong></td><td>" + Eval("HolidayHours") + "</td></tr>") %>


The error says: [CMSAbstractTransformation.DataBind]: Unable to cast object of type 'System.Boolean' to type 'System.String'.

User avatar
Member
Member
rebecca.wells - 7/14/2009 1:23:01 PM
   
RE:Help me please (Transformation)
Nevermind... with some trial and error I found that if I changed the "True" to 0 (zero), then the statement works.

User avatar
Member
Member
Jagr - 7/27/2009 8:11:49 AM
   
RE:Help me please (Transformation)
Hello,

I have the similar problem with IfCompare method...the method works fine if it has to present a link, for example.

But if the return value is True, I would like to generate a piece of code which contains my custom control. Is that possible to do somehow? I also must say that my control is registered, and when I use it outside IfCompare method it works perfectly.

The code I use, and that doesn't work is the following:

<%# IfCompare(Eval("Free"), "Free", "", "<uc1:MyControl id=\"" + Eval("FName") + "\" runat=\"server\"  />") %>


When I checked it using FireBug, I saw that this method didn't load my control.

User avatar
Member
Member
rebecca.wells - 7/27/2009 12:08:46 PM
   
RE:Help me please (Transformation)
I'm no expert, by maybe you could try changing it like this:
IfCompare(Eval("Free"), "True", ""

User avatar
Member
Member
rebecca.wells - 7/27/2009 12:10:25 PM
   
RE:Help me please (Transformation)
Du'oh! Didn't even follow my own earlier advice (use a 0 instead of True). Change it to this
IfCompare(Eval("Free"), "0", ""

User avatar
Member
Member
Jagr - 7/28/2009 3:00:00 AM
   
RE:Help me please (Transformation)
Hi Rebecca,

thanks for replying.

My field "Free" is string, and when I put the compare value it is working fine, and checking the condition.

For example, if the method returns "true", it is working fine and it writes the following code:

<a href="www.google.com>Google</a>


But if I put my user control instead of the <a> tag, it doesn't load the user control.

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 7/28/2009 7:07:45 AM
   
RE:Help me please (Transformation)
Hi Jagr,

Please do not use the control specification inside the IfCompare function. You could for example add your control directly in the transformation and use the condition in Visibility property of your control so that you can hide/show the control according your needs.

Are there any problems with this solution?

Best regards,
Helena Grulichova

User avatar
Member
Member
Jagr - 7/28/2009 7:52:28 AM
   
RE:Help me please (Transformation)
Hi Helena,

Everything works perfectly with Your solution.

Thank You...cheers :)

User avatar
Member
Member
humairsyed-gmail - 1/26/2010 9:09:04 AM
   
RE:Help me please (Transformation)
Hi,

I downloaded the zip file it has chm file but either links are broken or something is missing in the zip file, can you please provide with correct help file

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 1/26/2010 11:52:54 AM
   
RE:Help me please (Transformation)
Hello,

Could you please try the suggestions listed on this page? There are some tips on the bottom of the page.

Best regards,
Boris Pocatko