How to add PreValues programmatically into DropdownList in v8?
Hi folks,
I found some examples for v7 and earlier, but not for v8.
Anyone knows how to do this?
I have so far:
public static void SetDataTypePreValues(int id, List<string> values)
{
var dataTypeService = Current.Services.DataTypeService;
var dataType = dataTypeService.GetDataType(id); // this is the dropdownlist
// and now???
}
var valueList = (ValueListConfiguration)dataType.Configuration;
var lastId = valueList.Items.LastOrDefault()?.Id;
var newValueList = new List<ValueListConfiguration.ValueListItem>();
var idCounter = lastId ?? 0;
foreach (var val in values)
{
newValueList.Add(new ValueListConfiguration.ValueListItem
{
Id = idCounter,
Value = val
});
idCounter++;
}
((ValueListConfiguration)dataType.Configuration).Items.AddRange(newValueList);
dataTypeService.Save(dataType);
I don't know if this is the best way to do it, but at least it works.
How to add PreValues programmatically into DropdownList in v8?
Hi folks,
I found some examples for v7 and earlier, but not for v8. Anyone knows how to do this?
I have so far:
Thank you for your help.
Peter
What I did for now is:
I don't know if this is the best way to do it, but at least it works.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.