I seem to have a bit of trouble to add values to the checkbox list style. I have done a search on the forum and on google, but it still doesn't work for me :/
I have a set of prevalues for the checkbox list and I want to store the checked values on a given node when a frontend user clicks the "Save button"
The following code should set the values:
string listValues = string.Empty;
foreach (ListItem listItem in cblCategories.Items)
{
if (listItem.Selected)
listValues += listItem.Value.ToString() + ',';
}
if (listValues != string.Empty)
adDoc.getProperty("kategorier").Value = listValues;
If I try to switch the datatype in Umbraco to a textstring instead of the checkbox list, it writes the values as expected! So eventually they are able to be stored after a postback - or so it seems ;)
Set values in checkbox list programatically
Hi all,
I seem to have a bit of trouble to add values to the checkbox list style. I have done a search on the forum and on google, but it still doesn't work for me :/
I have a set of prevalues for the checkbox list and I want to store the checked values on a given node when a frontend user clicks the "Save button"
The following code should set the values:
If I try to switch the datatype in Umbraco to a textstring instead of the checkbox list, it writes the values as expected! So eventually they are able to be stored after a postback - or so it seems ;)
This is how I bind my checkbox list in Page_Load:
if (!Page.IsPostBack) { Node buySaleNode = new Node(1108); string cbl = buySaleNode.GetProperty("kategorier").Value; string[] categoryStrings = cbl.Split(','); cblCategories.DataSource = categoryStrings; cblCategories.DataBind(); }
I've also tried to bind the asp checkboxlist in the Page_Init event, but that didn't work either.
Have I missed something here? :)
Any hint/help on this is appreciated! Thanks!
All the best,
Bo
Hi Bo I am also having this issue, I have changed to textstring and my comma delimited list is saved OK. How did you end up resolving this?
Hi Barry,
Glad you asked, I completely forgot about this post :-)
The way I solved it was this:
http://www.bo-mortensen.dk/2011/09/working-with-umbraco-checkboxlist-prevalues/
All the best,
Bo
Hi Bo, The link does not work anymore. Can you help us with snippet here?
Thank you!
Ranjit
Hi Barry
How did you manage to do this? did you follow the article that Bo published?
Thanks
Paul
is working on a reply...