Created
September 14, 2011 19:47
-
-
Save leekelleher/1217575 to your computer and use it in GitHub Desktop.
U.S. States 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 USStates : AbstractDataEditor | |
{ | |
private DropDownList m_Control = new DropDownList(); | |
public IDictionary<string, string> StateDictionary = new Dictionary<string, string> | |
{ | |
{"Alabama", "AL"}, | |
{"Alaska", "AK"}, | |
{"American Samoa", "AS"}, | |
{"Arizona", "AZ"}, | |
{"Arkansas", "AR"}, | |
{"California", "CA"}, | |
{"Colorado", "CO"}, | |
{"Connecticut", "CT"}, | |
{"Delaware", "DE"}, | |
{"District of Columbia", "DC"}, | |
{"Federated States of Micronesia", "FM"}, | |
{"Florida", "FL"}, | |
{"Georgia", "GA"}, | |
{"Guam", "GU"}, | |
{"Hawaii", "HI"}, | |
{"Idaho", "ID"}, | |
{"Illinois", "IL"}, | |
{"Indiana", "IN"}, | |
{"Iowa", "IA"}, | |
{"Kansas", "KS"}, | |
{"Kentucky", "KY"}, | |
{"Louisiana", "LA"}, | |
{"Maine", "ME"}, | |
{"Marshall Islands", "MH"}, | |
{"Maryland", "MD"}, | |
{"Massachusetts", "MA"}, | |
{"Michigan", "MI"}, | |
{"Minnesota", "MN"}, | |
{"Mississippi", "MS"}, | |
{"Missouri", "MO"}, | |
{"Montana", "MT"}, | |
{"Nebraska", "NE"}, | |
{"Nevada", "NV"}, | |
{"New Hampshire", "NH"}, | |
{"New Jersey", "NJ"}, | |
{"New Mexico", "NM"}, | |
{"New York", "NY"}, | |
{"North Carolina", "NC"}, | |
{"North Dakota", "ND"}, | |
{"Northern Mariana Islands", "MP"}, | |
{"Ohio", "OH"}, | |
{"Oklahoma", "OK"}, | |
{"Oregon", "OR"}, | |
{"Palau", "PW"}, | |
{"Pennsylvania", "PA"}, | |
{"Puerto Rico", "PR"}, | |
{"Rhode Island", "RI"}, | |
{"South Carolina", "SC"}, | |
{"South Dakota", "SD"}, | |
{"Tennessee", "TN"}, | |
{"Texas", "TX"}, | |
{"Utah", "UT"}, | |
{"Vermont", "VT"}, | |
{"Virgin Islands", "VI"}, | |
{"Virginia", "VA"}, | |
{"Washington", "WA"}, | |
{"West Virginia", "WV"}, | |
{"Wisconsin", "WI"}, | |
{"Wyoming", "WY"} | |
}; | |
public override string DataTypeName | |
{ | |
get | |
{ | |
return "U.S. States"; | |
} | |
} | |
public override Guid Id | |
{ | |
get | |
{ | |
return new Guid("7B38C968-286E-4D3C-8C95-608CE3EA666C"); | |
} | |
} | |
public USStates() | |
{ | |
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.StateDictionary; | |
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; | |
} | |
} | |
} |
Am I missing something? This is not working for me. I'm using Umbraco 7.2.8.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The list of states was copied from an answer on the StackOverflow question: ASP.NET MVC US State Drop Down List