Skip to content

Instantly share code, notes, and snippets.

@leekelleher
Created September 14, 2011 19:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save leekelleher/1217575 to your computer and use it in GitHub Desktop.
Save leekelleher/1217575 to your computer and use it in GitHub Desktop.
U.S. States DropDownList DataType for Umbraco
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;
}
}
}
@leekelleher
Copy link
Author

The list of states was copied from an answer on the StackOverflow question: ASP.NET MVC US State Drop Down List

@FunkyMonk81
Copy link

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