views:

451

answers:

1

Anyone have have a dropdownlist helper method with a list of Canadian Provinces?

Based upon this question I was looking to find a Canadian Province equivalent. Hopefully this will save someone some extra typing, or lead to an even better answer.

+4  A: 
public class CanadianProvinces
{
    public static readonly IDictionary<string, string> ProvinceDictionary = new Dictionary<string, string>
                                                                             {
                                                                                 {"ALBERTA", "AB"},
                                                                                 {"BRITISH COLUMBIA", "BC"},
                                                                                 {"MANITOBA", "MB"},
                                                                                 {"NEW BRUNSWICK", "NB"},
                                                                                 {"NEWFOUNDLAND AND LABRADOR", "NL"},
                                                                                 {"NORTHWEST TERRITORIES", "NT"},
                                                                                 {"NOVA SCOTIA", "NS"},
                                                                                 {"NUNAVUT", "NU"},
                                                                                 {"ONTARIO", "ON"},
                                                                                 {"PRINCE EDWARD ISLAND", "PE"},
                                                                                 {"QUEBEC", "QC"},
                                                                                 {"SASKATCHEWAN", "SK"},
                                                                                 {"YUKON", "YT"},
                                                                             };

    public static SelectList ProvinceSelectList
    {
        get { return new SelectList(ProvinceDictionary, "Value", "Key"); }
    }

}

And then it is used in the following manner:

<%= Html.DropDownList("province", CanadianProvinces.ProvinceSelectList)%>
Josh Hawthorne
+1 Awesome. Thanks for this. Very timely. Not for Canadian provinces but for a host of other guff.
griegs