Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > How can I retrieve multiple choice field options using API View modes: 
User avatar
Member
Member
joeh42 - 1/18/2012 4:04:11 PM
   
How can I retrieve multiple choice field options using API
I just upgraded to Kentico 6. I'm looking at the sample code in http://devnet.kentico.com/Forums.aspx?forumid=45&threadid=23581 in order to get a multiple choice field out of the database.

While debugging, I can see that itemNode.Value = "0;Member landing page\r\n1;Footer links".

Why isn't the value of the node in the correct format? The text and value strings are not parsing out correctly.

Can Kentico provide the correct way to access this?

The values I had specified the options field were:
0;Member landing page
1;Footer links

Thanks,
Joe Hoppe

User avatar
Member
Member
kentico_michal - 1/20/2012 6:19:17 AM
   
RE:How can I retrieve multiple choice field options using API
Hello,

Kentico CMS 6.0 stores this options in different format. Therefore, you will need to parse the string, as it demonstrated here:


DataClassInfo info = DataClassInfoProvider.GetDataClass("<class name>");
if (info != null)
{
CMS.FormEngine.FormInfo fi = new CMS.FormEngine.FormInfo(info.ClassFormDefinition);
CMS.FormEngine.FormFieldInfo ffi = fi.GetFormField("<field name>");

string options = ValidationHelper.GetString((ffi.Settings["options"]), String.Empty);

options = options.Replace(FormHelper.SEMICOLON_TO_REPLACE, FormHelper.REPLACED_SEMICOLON);

string[] lines = options.Split(new string[] { Environment.NewLine, "\n" }, StringSplitOptions.RemoveEmptyEntries);
if (lines.Length > 0)
{
string text;
string value;

foreach (string line in lines)
{
// Insert hidden semicolons
value = line.Substring(0, line.IndexOf(";"));
value = value.Replace(FormHelper.REPLACED_SEMICOLON, ";");
text = line.Substring(line.IndexOf(";") + 1);
text = text.Replace(FormHelper.REPLACED_SEMICOLON, ";");
}
}
}


Best regards,
Michal Legen