Copied to clipboard

Flag this post as spam?

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


  • Laura Holland 82 posts 103 karma points
    Oct 24, 2009 @ 02:54
    Laura Holland
    0

    Checkbox List datatype - writing data from usercontrol?

    Hello All,

    I have an ascx usercontrol that is writing to custom member fields. I have successfully gotten my checkbox list in my ascx file to load my prevalues from Umbraco using xpath, but now I can't quite figure out how to get the user's selections from the checkbox list saved. I don't understand how this datatype is constructed... This is what I have now, based on my best guess, which isn't at all working:

    Dim TechTopic As ListItem
    Dim TechTypeString As String
    TechTypeString = ""
    For Each TechTopic In TechType.Items
    If TechTopic.Selected = True Then
    TechTypeString = TechTypeString + "," + TechTopic.Text
    End If
    Next
    newMember.getProperty("TechType").Value = TechTypeString

    How do I go about writing to the checkboxlist umbraco datatype, from a checkboxlist in a usercontrol?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Oct 24, 2009 @ 22:25
    Dirk De Grave
    0

    Hi Laura,

    I'm not completely sure how the value of this datatype is stored, but best way to find out is to check the umbraco.config from the /data folder, find a document which has a property of type 'Checkbox list' and see how that data is stored. Once the format is known, you should probably have to do the same with your custom member property.

     

    Hope this helps.

    Regards,

    /Dirk

  • Masood Afzal 176 posts 522 karma points
    Oct 24, 2009 @ 23:59
    Masood Afzal
    0

    c# code for saving member properties would be something like this:

    newMember.getProperty("alias").Value = "value";

    newMember.XmlGenerate(new System.Xml.XmlDocument());
    newMember.Save();
  • Masood Afzal 176 posts 522 karma points
    Oct 25, 2009 @ 00:01
  • Laura Holland 82 posts 103 karma points
    Oct 26, 2009 @ 19:22
    Laura Holland
    0

    I'm still not having any luck with this, after many unfruitful hours.. I've delved into the umbraco database and can see in the cmsPropertyData table where member additional member info is saved. I see that the umbraco checkboxlist datatype stores as a comma delimited list of the prevalue ID. So I need to iterate through my asp.net checkbox list, and save the value (not text) of the checked items as a string. The value I need is the ID from the cmsDataTypePreValues table.. But I can't get this to work... what am I missing?

    To populate my checkbox list I successfully use this code:

    Protected Sub LoadTechList()
            Dim TechTypeDataTypeNodeID As Integer = 1079
            Dim dataType As New Document(TechTypeDataTypeNodeID)
            Dim preValueRootElementIterator As XPathNodeIterator = umbraco.library.GetPreValues(1079)
            preValueRootElementIterator.MoveNext()
            'move to first

            Dim preValueIterator As XPathNodeIterator = preValueRootElementIterator.Current.SelectChildren("preValue", "")
            Dim TechTypeListItems As New ListItemCollection()

            While preValueIterator.MoveNext()
                TechTypeListItems.Add(New ListItem(" " + preValueIterator.Current.Value, preValueIterator.Current.GetAttribute("id", "")))
            End While

            'Bind data to checkbox list
            TechType.DataSource = TechTypeListItems
            TechType.DataTextField = "Text"
            TechType.DataValueField = "Value"
            TechType.DataBind()
        End Sub

    And to iterate through the checkboxlist control and save the selections to string:

    Dim checkedValues As String = ""
                For Each item As ListItem In TechType.Items
                    If item.Selected Then
                        checkedValues += item.Value + ","
                    End If
                Next
                newMember.getProperty("TechType").Value = checkedValues
                newMember.Save()

    I think the DataValueField binding isn't working. The form works without errors, but nothing from the checkboxlist is saved to the db. All my other custom member fields save to the table without problems.

  • Laura Holland 82 posts 103 karma points
    Oct 30, 2009 @ 21:12
    Laura Holland
    0

    FYI: I gave up on having the checkboxlist values bind to the umbraco prevalues. I ended up recreating the list, with the values in the ascx uercontrol matching the values in the umbraco db. It wasn't worth the effort, since I don't think this form will be updated very much, if at all. However, it would have been a nice feature, if I could have gotten it to work, since then the site administrator wouldn't need me to update the ascx file if he decides to change the values in the checkboxlist.

  • Sean Mooney 131 posts 158 karma points c-trib
    Oct 30, 2009 @ 21:47
    Sean Mooney
    1

    I use the following code to bind prevalues to an asp.net control:

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not Page.IsPostBack Then
                ddlType.DataSource = PreValues.GetPreValues(1079).GetValueList()
                ddlType.DataTextField = "Value"
                ddlType.DataValueField = "ID"
                ddlType.DataBind()
            End If
        End Sub
    
Please Sign in or register to post replies

Write your reply to:

Draft