Solved

Adding static values to drop down list

Posted on 2007-04-11
2
279 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 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

11 Experts available now in Live!

Get 1:1 Help Now