Created
July 29, 2011 13:49
-
-
Save sclarson/1113836 to your computer and use it in GitHub Desktop.
Fill list controls from episerver custom property settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void SetSelectedMultipleItemPropertyValues(string propertyName, ListControl control) | |
{ | |
var listValues = EditModel[propertyName] == null ? new List<string>() : EditModel[propertyName].ToString().Split(',').ToList(); | |
foreach (var option in GetMultipleOptionsListItemsForProperty(propertyName).ListOptions) | |
{ | |
var newItem = new ListItem(option.Key, option.Value); | |
if (!control.Items.Contains(newItem)) | |
control.Items.Add(newItem); | |
} | |
for (int i = 0; i < control.Items.Count; i++) | |
{ | |
if (listValues.Contains(control.Items[i].Value)) | |
control.Items[i].Selected = true; | |
} | |
} | |
private MultipleOptionsListSettings GetMultipleOptionsListItemsForProperty(string propertyName) | |
{ | |
IPropertySettingsRepository settingsRepository = new PropertySettingsRepository(); | |
PropertySettingsContainer container; | |
if (settingsRepository.TryGetContainer(EditModel.Property[propertyName].SettingsID, out container)) | |
{ | |
var wrapper = new PropertySettingsWrapper(); | |
foreach (PropertySettingsWrapper wrap in container.Settings.Values) | |
{ | |
if (wrap.PropertySettings.GetType() == typeof(MultipleOptionsListSettings)) | |
{ | |
wrapper = wrap; | |
break; | |
} | |
} | |
return wrapper.PropertySettings as MultipleOptionsListSettings; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment