Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jan 22, 2011 @ 11:49
    Bo Damgaard Mortensen
    0

    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:

    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 ;)

    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

  • Barry Fogarty 493 posts 1129 karma points
    Sep 03, 2011 @ 11:47
    Barry Fogarty
    0

    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?

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Sep 04, 2011 @ 10:56
    Bo Damgaard Mortensen
    0

    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

     

  • Ranjit J. Vaity 65 posts 108 karma points
    Feb 26, 2022 @ 22:05
    Ranjit J. Vaity
    0

    Hi Bo, The link does not work anymore. Can you help us with snippet here?

    Thank you!

    Ranjit

  • Paul Griffiths 362 posts 1013 karma points
    Feb 12, 2014 @ 15:54
    Paul Griffiths
    0

    Hi Barry

    How did you manage to do this? did you follow the article that Bo published?

    Thanks

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft