Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Custom user filter drop list values View modes: 
User avatar
Member
Member
Dev_Ryan - 11/17/2011 3:59:21 AM
   
Custom user filter drop list values
I want to create a Custom user filter. The filter will include CMS.User custom fields that are defined as drop lists. The values for these drop lists are defined for each field as value;name pairs via site manager. How do I retrieve the drop list values to fill the drop lists in my custom user filter webpart?

User avatar
Member
Member
kentico_michal - 11/17/2011 11:26:08 PM
   
RE:Custom user filter drop list values
Hello,

This information is stored as a part of field definition. Please take a look at the following code snippet that shows how you can get text/value pairs for a field:


DataClassInfo info = DataClassInfoProvider.GetDataClass("cms.user");
if (info != null)
{
CMS.FormEngine.FormInfo fi = new CMS.FormEngine.FormInfo(info.ClassFormDefinition);
// here you need to specify a field
CMS.FormEngine.FormFieldInfo ffi = fi.GetFormField(<field name>");

System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.LoadXml("<xml>" + Convert.ToString(ffi.Settings["options"]) + "</xml>");

System.Xml.XmlNode xmlNode = xmlDoc.FirstChild;

if (xmlNode.HasChildNodes)
{
// loop through all options
foreach (System.Xml.XmlNode itemNode in xmlNode.ChildNodes)
{
// get text/value pair
string text = CMSContext.CurrentResolver.ResolveMacros(XmlHelper.GetAttributeValue(itemNode, "text"));
string value = CMSContext.CurrentResolver.ResolveMacros(XmlHelper.GetAttributeValue(itemNode, "value"));
}
}
}


I hope this will help you.

Best regards,
Michal Legen

User avatar
Member
Member
Dev_Ryan - 11/18/2011 5:48:02 AM
   
RE:Custom user filter drop list values
Thank you! This is exactly what I needed.