I looked for a while on how to transform pipe-delimited values from a field list-box and couldn't find anything specific - only general information about how to write a transformation method. So, I did that and tried to make it pretty generic and thought I'd share what I came up with. If anyone has any suggestions for improvement, they would be greatly appreciated.
public static string Lookup(object _value, string _classNames, string _valueField, string _textField)
{
NodeSelectionParameters _params = new NodeSelectionParameters();
_params.SelectOnlyPublished = true;
_params.SiteName = CMS.CMSHelper.CMSContext.CurrentSiteName;
_params.ClassNames = _classNames;
_params.Where = _valueField + " IN (" + _value.ToString().Replace('|',',') + ")";
_params.OrderBy = _valueField;
TreeProvider _tree = new TreeProvider();
var _dataSet = _tree.SelectNodes(_params);
if (_dataSet != null)
{
StringWriter stringWriter = new StringWriter();
using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter))
{
var _nodes = _dataSet.Items;
if(_nodes.Count == 1){
writer.Write(ValidationHelper.GetString(_nodes[0][_textField], String.Empty));
} else {
writer.RenderBeginTag(HtmlTextWriterTag.Ul);
foreach (CMS.DocumentEngine.TreeNode _node in _nodes)
{
writer.RenderBeginTag(HtmlTextWriterTag.Li);
writer.Write(ValidationHelper.GetString(_node[_textField], String.Empty));
writer.RenderEndTag();
}
writer.RenderEndTag();
}
}
return stringWriter.ToString();
}
return "";
}