[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

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

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
Rouchie
Asked:
Rouchie
  • 2
2 Solutions
 
Ryan ChongCommented:
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
 
mantaraeCommented:
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
 
RouchieAuthor Commented:
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
 
mantaraeCommented:
Nope, there isn't an automatic way to get a-z.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now