Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi all, I have such code that created new node in Umbraco.
IContent story = contentService.CreateContent(model.StoryTitle, folderId, "successStory", 0); story.SetValue("storyStates", model.States);
How I can set value in CheckBox List property?
As far as I remember a checkbox list contains a comma-separated list of Ids. So you can set it like:
story.SetValue("checkboxList", "1,2,3,4,5");
or
var values = new int[] { 1, 2, 3, 4, 5 }; story.SetValue("checkboxList", String.Join(",", values));
Dan Diplo Thank you very much! It's solved my problem.
This has changed in Umbraco V13. The Checkbox List datatype now contains string representation of an array, containing a CSV.
So where @Dan Diplo's
var values = new int[] { 1, 2, 3, 4, 5 };story.SetValue("checkboxList", String.Join(",", values));
would create the value 1, 2, 3, 4, 5, you'd now need to create a string which contains the square brackets, like [1, 2, 3, 4, 5]
1, 2, 3, 4, 5
[1, 2, 3, 4, 5]
Updated code:
var values = new int[] { 1, 2, 3, 4, 5 };story.SetValue("checkboxList", $"[{String.Join(",", values )}]");
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Set values in CheckBox List code behind
Hi all, I have such code that created new node in Umbraco.
How I can set value in CheckBox List property?
As far as I remember a checkbox list contains a comma-separated list of Ids. So you can set it like:
or
Dan Diplo Thank you very much! It's solved my problem.
This has changed in Umbraco V13. The Checkbox List datatype now contains string representation of an array, containing a CSV.
So where @Dan Diplo's
would create the value
1, 2, 3, 4, 5
, you'd now need to create a string which contains the square brackets, like[1, 2, 3, 4, 5]
Updated code:
is working on a reply...