Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > displaying the label of a dropdown menu instead of the value View modes: 
User avatar
Member
Member
paul.truman-sunmed.co - 8/22/2012 6:39:49 AM
   
displaying the label of a dropdown menu instead of the value
Bit of an easy one to solve hopefully - I'm using <%# Eval("Brand") %> in a transformation to display the value selected in a dropdown menu on a product. The only trouble is, it's using the value of the dropdown menu (e.g. 1) instead of the visible label "e.g. Blue"). Is there any way to display the label instead?

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 8/22/2012 7:05:04 AM
   
RE:displaying the label of a dropdown menu instead of the value
Hello,

This will require to create a custom macro (custom transformation method), which will get the class form definition according to the selected value. Please find some API example on manipulating the class form definition below:

using CMS.FormEngine;
using CMS.SettingsProvider;
...

DataClassInfo dci = DataClassInfoProvider.GetDataClass("cms.user");
if (dci != null)
{
FormInfo fi = new FormInfo(dci.ClassFormDefinition);
FormFieldInfo ffi = fi.GetFormField("UserIsExternal");
if (ffi != null)
{
// now you can work with the FormFieldInfo
FormFieldDataTypeEnum dataType = ffi.DataType;
}
}

Here is some example code for the object CMS.Article and the field MyDropdown:

//getting the DataClassInfo for the given object (e.g. cms.article)
CMS.SettingsProvider.DataClassInfo di = CMS.SettingsProvider.DataClassInfoProvider.GetDataClass("CMS.Article");

//creating a new FormInfo object
CMS.FormEngine.FormInfo fi = new CMS.FormEngine.FormInfo(di.ClassFormDefinition);

//getting the field
CMS.FormEngine.FormFieldInfo ffi = fi.GetFormField("MyDropdown");

//acessing all the fields options
Label1.Text = ffi.Settings["Options"].ToString();

Best regards,
Boris Pocatko