Created
May 24, 2013 11:02
-
-
Save leekelleher/5642735 to your computer and use it in GitHub Desktop.
London Boroughs DropDownList DataType for Umbraco
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
using System; | |
using System.Collections.Generic; | |
using System.Web.UI.WebControls; | |
using umbraco.cms.businesslogic.datatype; | |
namespace Our.Umbraco.DataTypes | |
{ | |
public class LondonBoroughs : AbstractDataEditor | |
{ | |
private DropDownList m_Control = new DropDownList(); | |
// ref: http://en.wikipedia.org/wiki/London_boroughs | |
public IDictionary<string, string> BoroughDictionary = new Dictionary<string, string> | |
{ | |
{ "Barking and Dagenham", "barking-and-dagenham" }, | |
{ "Barnet", "barnet" }, | |
{ "Bexley", "bexley" }, | |
{ "Brent", "brent" }, | |
{ "Bromley", "bromley" }, | |
{ "Camden", "camden" }, | |
{ "City of London", "city-of-london" }, | |
{ "City of Westminster", "city-of-westminster" }, | |
{ "Croydon", "croydon" }, | |
{ "Ealing", "ealing" }, | |
{ "Enfield", "enfield" }, | |
{ "Greenwich", "greenwich" }, | |
{ "Hackney", "hackney" }, | |
{ "Hammersmith and Fulham", "hammersmith-and-fulham" }, | |
{ "Haringey", "haringey" }, | |
{ "Harrow", "harrow" }, | |
{ "Havering", "havering" }, | |
{ "Hillingdon", "hillingdon" }, | |
{ "Hounslow", "hounslow" }, | |
{ "Islington", "islington" }, | |
{ "Kensington and Chelsea", "kensington-and-chelsea" }, | |
{ "Kingston upon Thames", "kingston-upon-thames" }, | |
{ "Lambeth", "lambeth" }, | |
{ "Lewisham", "lewisham" }, | |
{ "Merton", "merton" }, | |
{ "Newham", "newham" }, | |
{ "Redbridge", "redbridge" }, | |
{ "Richmond upon Thames", "richmond-upon-thames" }, | |
{ "Southwark", "southwark" }, | |
{ "Sutton", "sutton" }, | |
{ "Tower Hamlets", "tower-hamlets" }, | |
{ "Waltham Forest", "waltham-forest" }, | |
{ "Wandsworth", "wandsworth" } | |
}; | |
public override string DataTypeName | |
{ | |
get | |
{ | |
return "London Boroughs (DropDownList)"; | |
} | |
} | |
public override Guid Id | |
{ | |
get | |
{ | |
return new Guid("9C073C92-3649-4E58-9924-E3045E5A3F20"); | |
} | |
} | |
public LondonBoroughs() | |
{ | |
base.RenderControl = this.m_Control; | |
this.m_Control.Init += new EventHandler(this.m_Control_Init); | |
base.DataEditorControl.OnSave += new AbstractDataEditorControl.SaveEventHandler(this.DataEditorControl_OnSave); | |
} | |
private void m_Control_Init(object sender, EventArgs e) | |
{ | |
this.m_Control.DataSource = this.BoroughDictionary; | |
this.m_Control.DataTextField = "Key"; | |
this.m_Control.DataValueField = "Value"; | |
this.m_Control.DataBind(); | |
if (base.Data.Value != null) | |
{ | |
this.m_Control.SelectedValue = base.Data.Value.ToString(); | |
} | |
} | |
private void DataEditorControl_OnSave(EventArgs e) | |
{ | |
base.Data.Value = this.m_Control.SelectedValue; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment