Quick way of displaying A-Z options in a DropDownList?

Posted on 2004-10-21
Last Modified: 2008-03-04
Currently I have a DropDownList that displays the options A-Z as follows;

<asp:DropDownList runat="server" id="letterList" >
    <asp:ListItem value="a">A</asp:ListItem>
    <asp:ListItem value="b">B</asp:ListItem>
    <asp:ListItem value="z">Z</asp:ListItem>

Is there any way to achieve this quickly using some sort of looping functionality etc??
Question by:Rouchie
    LVL 48

    Assisted Solution

    by:Ryan Chong
    try look for the DataSource property of the DropDownList , like:

    In the Page_Load()

    letterList.DataSource = myList

    where myList is an array contains A to Z

    hope this helps
    LVL 7

    Accepted Solution

    declare a string array with the letters:
    string[] letters = {"a", "b", "c", "d"}; //etc..

    for (int i=0; i<letters.Length; i++){
        ListItem li = new ListItem(letters[i], letters[i]);
    LVL 25

    Author Comment

    The main reason I asked was so that I didn't have to write out all the letters of the alphabet.  Both examples unfortuntely employ that method.  Is there no functionality in .NET to loop through letters like there are numbers??
    LVL 7

    Expert Comment

    Nope, there isn't an automatic way to get a-z.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    877 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now