for loop for dropdownlist

Posted on 2005-04-06
Last Modified: 2010-04-16
Hi, I would like to have a for loop which fills the same values from a database into 3 dropdownlists
Something like this:

for (int i = 0; i < 3 ; i++)
DropDownList4.DataSource = cmd.ExecuteReader();
DropDownList4.DataTextField = "USER_NAME";
DropDownList4.DataValueField = "USER_NAME";

Where as the number 4 should be replaced by the i value. Is that possible?


Question by:ccoe1
    LVL 6

    Accepted Solution

    Hi Chris,

    Sounds like you could benefit from the implementation of a Control Array.  Then you could just use your (i) value to represent the index value of the array.  For an easy-to-follow example of implementing Control Arrays in C# go to:

    Hope this helps.


    Jack Pick
    Total Data Solutions
    LVL 6

    Expert Comment

    I believe my answer was helpful.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    761 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

    7 Experts available now in Live!

    Get 1:1 Help Now