Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Adding static values to drop down list

Posted on 2007-04-11
2
306 Views
Last Modified: 2008-02-01
I need to add several static values to a drop down list in c#. e.g. 01, -12. I know I can achieve this through a "for loop", but I would like to use the actual values (maybe through some array of sorts?)
0
Comment
Question by:felkamau
  • 2
2 Comments
 
LVL 4

Expert Comment

by:CBeach1980
ID: 18893233
Create an ArrayList to store the values:
ArrayList values = new ArrayList();
values.add("val1");
values.add("val2");
values.add("val3");
etc...

for (int i=0; i < values.Count; i++)
   dropDownList.Items.Add(values[i].ToString());
0
 
LVL 4

Accepted Solution

by:
CBeach1980 earned 500 total points
ID: 18893246
Better yet...

Create an ArrayList to store the values:
ArrayList values = new ArrayList();
values.add("val1");
values.add("val2");
values.add("val3");
etc...

dropDownList.DataSource = values;
dropDownList.DataBind();
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What is "public object" in C#? 3 64
C# Printing Labels to locally attached DYMO LabelWriter 450 printer (via USB port) via WCF Service 5 64
MediaHelp 4 26
Problem!!! 8 37
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

808 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