Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Get the Display Value of a DropDownList Control in a Transformation View modes: 
User avatar
Member
Member
SaLiMoS - 10/26/2010 9:04:45 AM
   
Get the Display Value of a DropDownList Control in a Transformation
Hello Guys,
I just want to know if i have a Document Type with a Field of type DropDownList and i entered the Options Manually like the following:
1;option1
2;option2

If in the transformation i put <%# Eval("Category")%> i am getting the value which is "1 or 2" how can i get the Display value "option 1 or option 2"

Regards,

User avatar
Member
Member
kentico_michal - 11/1/2010 4:14:06 PM
   
RE:Get the Display Value of a DropDownList Control in a Transformation
Hi,

Please keep in mind that the first value from the pair (for example 1;option1 ) is stored in the database (value 1 in this case) and the second one (string option1) is used only to display in drop-down list.

Eval method use value from database, so this is the reason why value 1 is displayed.

One way how to achieve displaying Option1 (or Option2) could be based on custom transformation method (please find more information in Developer's guide http://devnet.kentico.com/docs/devguide/index.html?adding_custom_functions_to_transformations.htm).

You could use for example following code in that custom method:

public static string customFunction(object input)
{
string option = (string)input;
if (option.Equals("1")) return "Option 1";
else if (option.Equals("2")) return "Option 2";
return "Undefined";
}


<%# MyFunctions.customFunction(Eval("fieldName")) %>


Second way could be changing the way how you define drop-down list options to following definition, so that string Option1 was stored in database instead of value 1:

Option1;option1


Best regards,
Michal Legen

User avatar
Member
Member
SaLiMoS - 11/2/2010 2:12:06 AM
   
RE:Get the Display Value of a DropDownList Control in a Transformation
Hi Michal,
Thank you for your reply,
Well i have tried the second Option but in my case it will not work because i have a multi Language website where the definition is like follow:
1;{$=English|fr-FR= French$}

I tried Putting it like this:
{$=English|fr-FR= French$}; {$=English|fr-FR= French$}

But it didn't work.
Therefore i think i will follow the first way using custom functions.

Thank you.
Salim Awad

User avatar
Member
Member
kentico_michal - 11/12/2010 5:44:57 AM
   
RE:Get the Display Value of a DropDownList Control in a Transformation
Hi,

Well, in this case you can use following function in your custom transformation method to get information about current document culture and return appropriate value depending on it :

string culture = CMS.CMSHelper.CMSContext.CurrentDocumentCulture.CultureCode;

Best regards,
Michal Legen