Copied to clipboard

Flag this post as spam?

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


  • andy_rose 91 posts 117 karma points
    Sep 08, 2009 @ 17:40
    andy_rose
    0

    Programatically adding values to a checkbox list

    I've been trying various options to add values to a custom checkbox list datatype property in a document as part of a content import process but so far none of them have worked. I have checked the database and seen that the data is stored in the following format:

    <data alias="myAlias"><![CDATA[item1,item2,item4]]></data>

    I have used the following variations in code to store some imported values:

    • myDocument.getProperty("myAlias").Value = "item1,item2,item4";
    • myDocument.getProperty("myAlias").Value = "[item1,item2,item4]";
    • myDocument.getProperty("myAlias").Value = "<![CDATA[item1,item2,item4]]>";

    However when I check the database nothing has been stored. Has anyone got any idea how I can go about doing this or why this is not currently working? The database datatype is currently set to Nvarchar.

  • Paul Sterling 719 posts 1556 karma points MVP 9x admin c-trib
    Sep 08, 2009 @ 18:38
    Paul Sterling
    0

    Andy -

    An indirect solution for you from my similar solution to a list box type.  This is implemented as a User Control and wrapped as a Custom Data Type.

    First, when the control loads we populate the list:

                    // load list items
                    string[] namesArray = ListData.Split(',');
                    List<ListItem> namesList = new List<ListItem>(namesArray.Length);

                    foreach (string item in namesArray)
                    {
                        ItemList.Items.Add(item);
                    }

    the, we add items to the list based on an action (button click or similar):

                // set to string
                string listValues = string.Empty;

                foreach (ListItem listItem in ItemList.Items)
                {
                    if (listItem.Value.Length > 0)
                    listValues += listItem.Value.ToString() + ',';
                }

                if (listValues != string.Empty)
                    ListData = listValues;

    Certainly, room for improvement, but hopefully a start.

    -Paul

     

  • andy_rose 91 posts 117 karma points
    Sep 09, 2009 @ 10:13
    andy_rose
    0

    Thank you for the response Paul but unfortunately I don't think I've made myself clear in what i'm trying to achieve.

    I have created a document type that has a number of properties one of which is a custom checkbox list type with a set of predefined values. My import process is then creating a series of content pages using this document type and populating the properties from values held in a database and then publishing the page. The problem is trying to set the values in the checkbox list from the data held in the database.

    If I create a page using this content type via the dashboard and then select some of the checkbox list items before publishing the page I have seen that the selected items are stored within the text of the xml column of the cmsContentXml table for the particular node id in this format:

    <data alias="myAlias"><![CDATA[item1,item2,item4]]></data>

    I have been attempting to recreate this progamatically as shown above but so far have not had any success.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Sep 09, 2009 @ 11:00
    Thomas Höhler
    1

    You have to add the Values (integers) as list into the property:

    "74,75,76" instead of "item1,item2,item3"

    Thomas

  • andy_rose 91 posts 117 karma points
    Sep 09, 2009 @ 11:15
    andy_rose
    0

    Thanks Thomas, just had this revelation myself. There are days when I think I shouldn't be allowed to sit in front of a computer.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Sep 09, 2009 @ 11:16
    Thomas Höhler
    0

    LOL

Please Sign in or register to post replies

Write your reply to:

Draft