Skip to content

Instantly share code, notes, and snippets.

@mikeedwards83
Created July 22, 2012 09:35
Show Gist options
  • Select an option

  • Save mikeedwards83/3159070 to your computer and use it in GitHub Desktop.

Select an option

Save mikeedwards83/3159070 to your computer and use it in GitHub Desktop.
Read and writing data
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