• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 994
  • Last Modified:

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

Hi,

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";
                    }
                }
            }

Thanks
0
jgerbitz
Asked:
jgerbitz
  • 2
1 Solution
 
p_davisCommented:
is there a page.controls ?
0
 
p_davisCommented:
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)
0
 
jgerbitzAuthor Commented:
Thanks, that's the ticket.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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