Web Resources   >   .NET   >   DropDownList of States
March 29, 2017

It is difficult to find a code snippet of a dropdownlist control populated with a list of all 50 U.S. states. 

<asp:DropDownList ID="ddlStates" runat="server">
    <asp:ListItem Value="AL">Alabama asp:ListItem>
<asp:ListItem Value="AK">Alaska asp:ListItem>
<asp:ListItem Value="AZ">Arizona asp:ListItem>
<asp:ListItem Value="AR">Arkansas asp:ListItem>
<asp:ListItem Value="CA">California asp:ListItem>
<asp:ListItem Value="CO">Colorado asp:ListItem>
<asp:ListItem Value="CT">Connecticut asp:ListItem>
<asp:ListItem Value="DE">Delaware asp:ListItem>
<asp:ListItem Value="FL">Florida asp:ListItem>
<asp:ListItem Value="GA">Georgia asp:ListItem>
<asp:ListItem Value="HI">Hawaii asp:ListItem>
<asp:ListItem Value="ID">Idaho asp:ListItem>
<asp:ListItem Value="IL">Illinois asp:ListItem>
<asp:ListItem Value="IN">Indiana asp:ListItem>
<asp:ListItem Value="IA">Iowa asp:ListItem>
<asp:ListItem Value="KS">Kansas asp:ListItem>
<asp:ListItem Value="KY">Kentucky asp:ListItem>
<asp:ListItem Value="LA">Louisiana asp:ListItem>
<asp:ListItem Value="ME">Maine asp:ListItem>
<asp:ListItem Value="MD">Maryland asp:ListItem>
<asp:ListItem Value="MA">Massachusetts asp:ListItem>
<asp:ListItem Value="MI">Michigan asp:ListItem>
<asp:ListItem Value="MN">Minnesota asp:ListItem>
<asp:ListItem Value="MS">Mississippi asp:ListItem>
<asp:ListItem Value="MO">Missouri asp:ListItem>
<asp:ListItem Value="MT">Montana asp:ListItem>
<asp:ListItem Value="NE">Nebraska asp:ListItem>
<asp:ListItem Value="NV">Nevada asp:ListItem>
<asp:ListItem Value="NH">New Hampshire asp:ListItem>
<asp:ListItem Value="NJ">New Jersey asp:ListItem>
<asp:ListItem Value="NM">New Mexico asp:ListItem>
<asp:ListItem Value="NY">New York asp:ListItem>
<asp:ListItem Value="NC">North Carolina asp:ListItem>
<asp:ListItem Value="ND">North Dakota asp:ListItem>
<asp:ListItem Value="OH">Ohio asp:ListItem>
<asp:ListItem Value="OK">Oklahoma asp:ListItem>
<asp:ListItem Value="OR">Oregon asp:ListItem>
<asp:ListItem Value="PA">Pennsylvania asp:ListItem>
<asp:ListItem Value="RI">Rhode Island asp:ListItem>
<asp:ListItem Value="SC">South Carolina asp:ListItem>
<asp:ListItem Value="SD">South Dakota asp:ListItem>
<asp:ListItem Value="TN">Tennessee asp:ListItem>
<asp:ListItem Value="TX">Texas asp:ListItem>
<asp:ListItem Value="UT">Utah asp:ListItem>
<asp:ListItem Value="VT">Vermont asp:ListItem>
<asp:ListItem Value="VA">Virginia asp:ListItem>
<asp:ListItem Value="WA">Washington asp:ListItem>
<asp:ListItem Value="WV">West Virginia asp:ListItem>
<asp:ListItem Value="WI">Wisconsin asp:ListItem>
<asp:ListItem Value="WY">Wyoming asp:ListItem>
asp:DropDownList>
And here is an arraylist already created
 

[System.ComponentModel. DataObjectMethodAttribute (System.ComponentModel. DataObjectMethodType .Select, false )]

public ArrayList GetAllStates()

{

ArrayList al = new ArrayList();

al.Add(new ListItem("-1", "--Select State--"));

al.Add(new ListItem("AL", "Alabama"));

al.Add(new ListItem("AK", "Alaska"));

al.Add(new ListItem("AZ", "Arizona"));

al.Add(new ListItem("AR", "Arkansas"));

al.Add(new ListItem("CA", "California"));

al.Add(new ListItem("CO", "Colorado"));

al.Add(new ListItem("CT", "Connecticut"));

al.Add(new ListItem("DE", "Delaware"));

al.Add(new ListItem("FL", "Florida"));

al.Add(new ListItem("GA", "Georgia"));

al.Add(new ListItem("HI", "Hawaii"));

al.Add(new ListItem("ID", "Idaho"));

al.Add(new ListItem("IL", "Illinois"));

al.Add(new ListItem("IN", "Indiana"));

al.Add(new ListItem("IA", "Iowa"));

al.Add(new ListItem("KS", "Kansas"));

al.Add(new ListItem("KY", "Kentucky"));

al.Add(new ListItem("LA", "Louisiana"));

al.Add(new ListItem("ME", "Maine"));

al.Add(new ListItem("MD", "Maryland"));

al.Add(new ListItem("MA", "Massachusetts"));

al.Add(new ListItem("MI", "Michigan"));

al.Add(new ListItem("MN", "Minnesota"));

al.Add(new ListItem("MS", "Mississippi"));

al.Add(new ListItem("MO", "Missouri"));

al.Add(new ListItem("MT", "Montana"));

al.Add(new ListItem("NE", "Nebraska"));

al.Add(new ListItem("NV", "Nevada"));

al.Add(new ListItem("NH", "New Hampshire"));

al.Add(new ListItem("NJ", "New Jersey"));

al.Add(new ListItem("NM", "New Mexico"));

al.Add(new ListItem("NY", "New York"));

al.Add(new ListItem("NC", "North Carolina"));

al.Add(new ListItem("ND", "North Dakota"));

al.Add(new ListItem("OH", "Ohio"));

al.Add(new ListItem("OK", "Oklahoma"));

al.Add(new ListItem("OR", "Oregon"));

al.Add(new ListItem("PA", "Pennsylvania"));

al.Add(new ListItem("RI", "Rhode Island"));

al.Add(new ListItem("SC", "South Carolina"));

al.Add(new ListItem("SD", "South Dakota"));

al.Add(new ListItem("TN", "Tennessee"));

al.Add(new ListItem("TX", "Texas"));

al.Add(new ListItem("UT", "Utah"));

al.Add(new ListItem("VT", "Vermont"));

al.Add(new ListItem("VA", "Virginia"));

al.Add(new ListItem("WA", "Washington"));

al.Add(new ListItem("WV", "West Virginia"));

al.Add(new ListItem("WI", "Wisconsin"));

al.Add(new ListItem("WY", "Wyoming"));

return al;

}