How do you set a multi-select dropdown's value? (plus sample for single select included)
Below is a code snippet of how I am setting the value of a dropdown that is a single-selection dropdown. Can anyone tell me how you would set multiple values into the "value" property, is it simply a comma delimited list, or something else
/// <summary>
/// Set the default value of the specified property to the desired value if (and only if) the value is blank
/// or null.
/// </summary>
/// <param name="node">Current Content Node to update if needed</param>
/// <param name="propName">Property Name to set</param>
/// <param name="desiredDefaultValue">desired value (string) that the field should be set to</param>
private void SetDropDownListSingleValue(IContent node, string propName, string desiredDefaultValue)
{
if (node.HasProperty(propName))
{
var currentValue = node.Properties[propName].Value;
if (string.IsNullOrEmpty(DataUtilities.ObjectAsString(currentValue)))
{
var dtDefs = umbraco.library.GetPreValues(node.Properties[propName].PropertyType.DataTypeDefinitionId);
dtDefs.MoveNext();
foreach (XPathNavigator item in dtDefs.Current.SelectChildren("preValue", ""))
{
if (desiredDefaultValue.Equals(item.InnerXml, StringComparison.OrdinalIgnoreCase))
{
node.Properties[propName].Value = item.GetAttribute("id", "");
break;
}
}
ApplicationContext.Current.Services.ContentService.SaveAndPublishWithStatus(node);
}
}
}
How do you set a multi-select dropdown's value? (plus sample for single select included)
Below is a code snippet of how I am setting the value of a dropdown that is a single-selection dropdown. Can anyone tell me how you would set multiple values into the "value" property, is it simply a comma delimited list, or something else
Anyone? Anyone?
you've probably figured it out but it's comma separated list of prevalue id for anyone else who sees this
is working on a reply...