Solved

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

Posted on 2004-10-21
298 Views
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>
    ...etc
    <asp:ListItem value="z">Z</asp:ListItem>
</asp:DropDownList>

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

    Assisted Solution

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

    In the Page_Load()

    ...
    letterList.DataSource = myList
    letterList.DataBind()
    ...

    where myList is an array contains A to Z

    hope this helps
    0
     
    LVL 7

    Accepted Solution

    by:
    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]);
        letterList.Items.Add(li);
    }
    0
     
    LVL 25

    Author Comment

    by:Rouchie
    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??
    0
     
    LVL 7

    Expert Comment

    by:mantarae
    Nope, there isn't an automatic way to get a-z.
    0

    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: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
    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 (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. 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