Created
July 22, 2012 09:35
-
-
Save mikeedwards83/3159070 to your computer and use it in GitHub Desktop.
Read and writing data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protected override void OnInit(EventArgs e) | |
| { | |
| btn.Click += new EventHandler(btn_Click); | |
| var form = this.SitecoreContext.GetCurrentItem<Templates.EditableExample>(); | |
| base.OnInit(e); | |
| ddlExample.DataSource = form.TreeList; | |
| ddlExample.DataTextField = "Name"; | |
| ddlExample.DataValueField = "Id"; | |
| ddlExample.DataBind(); | |
| ///this assumes that the user profile you are working with is just another Sitecore item. | |
| var profile = this.SitecoreContext.GetItem<Profile>("/sitecore/profiles/myprofile"); | |
| if (profile != null) | |
| ddlExample.SelectedValue = profile.Value; | |
| } | |
| void btn_Click(object sender, EventArgs e) | |
| { | |
| var profile = this.SitecoreContext.GetItem<Profile>("/sitecore/profiles/myprofile"); | |
| profile.Value = ddlExample.SelectedValue; | |
| using (new SecurityDisabler()) | |
| { | |
| this.SitecoreContext.Save(profile); | |
| } | |
| } | |
| [SitecoreClass] | |
| public class Form | |
| { | |
| [SitecoreField] | |
| public virtual IEnumerable<Lookup> TreeList { get; set; } | |
| } | |
| [SitecoreClass] | |
| public class Lookup | |
| { | |
| [SitecoreId] | |
| public virtual Guid Id { get; set; } | |
| [SitecoreInfo(Configuration.SitecoreInfoType.Name)] | |
| public virtual string Name { get; set; } | |
| } | |
| [SitecoreClass] | |
| public class Profile | |
| { | |
| [SitecoreField] | |
| public string Value { get; set; } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment