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?
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.
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.
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.
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
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:
How do I go about writing to the checkboxlist umbraco datatype, from a checkboxlist in a usercontrol?
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
c# code for saving member properties would be something like this:
Have a look at this post
http://our.umbraco.org/forum/developers/extending-umbraco/2209-Custom-DataType---DropDownList-Value-Being-Lost
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:
And to iterate through the checkboxlist control and save the selections to string:
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.
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.
I use the following code to bind prevalues to an asp.net control:
is working on a reply...