h1

States Dropdown

October 22, 2009

No learning here, just something that I seem to end up copy-pasting a lot, so I’ll be able to find it easily here.. (And it’d be easy to do a find-replace all of ‘asp:ListItem’ to ‘option’ if it’s going to be used in an html page rather than an asp/aspx page. Also, the required field validator would need to be taken out; that’s only if you want it to be required for a state to be selected, before the form can be submitted.)

<asp:RequiredFieldValidator ControlToValidate="ddState" ID="Neko" runat="server" ErrorMessage="RequiredFieldValidator" Text="*" SetFocusOnError="true" />
State:
<asp:DropDownList ID="ddState" runat="server">
  <asp:ListItem Selected="True" value="">Choose A State</asp:ListItem>
  <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="DC">District of Columbia</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">Lousiana</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>

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.