foreach statement cannot operate on variables of type 'System.Web.UI.Page'

Posted on 2007-09-28
Last Modified: 2008-01-09

I'm trying to execute some code (VS 2005, C#) but am getting this error:

"foreach statement cannot operate on variables of type 'System.Web.UI.Page' because 'System.Web.UI.Page' does not contain a public definition for 'GetEnumerator'"

The code:

            foreach (Control cntl in Page)
                if (cntl is DropDownList)
                    DropDownList ddl;
                    if ((string)ddl.SelectedValue == "Select Reason")
                        ddl.SelectedValue = (string)"0";

Question by:jgerbitz
    LVL 22

    Expert Comment

    is there a page.controls ?
    LVL 22

    Accepted Solution

    when you iterate through something you have to match the types that you are trying to use

    like if i wanted to iterate through columns in a dataset
    i would have to say
    foreach(DataColumn dc in dataset.tables[0].columns)

    Author Comment

    Thanks, that's the ticket.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    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…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    731 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

    15 Experts available now in Live!

    Get 1:1 Help Now