Solved

Looping through controls

Posted on 2006-06-13
1
851 Views
Last Modified: 2012-06-21
I am trying to loop through all checkboxes in my webpage - they are located inside of a multiview control of ASP.NET 2.0.  This is the code I am using, but it does not work:

        foreach (Control ctl in MultiView1.Controls[1].Controls)
        {
            if (ctl is CheckBox)
            {
                CheckBox ch = (CheckBox)ctl;
                Response.Write(ch.Text + " ");
            }
        }

Any ideas?  I can't get it to work. :(

Thank you
0
Comment
Question by:stankstank
1 Comment
 
LVL 4

Accepted Solution

by:
jvn222 earned 500 total points
Comment Utility
Are you sure CheckBox controls located inside of the multiview

Use code below to test:

public void test()
{
      foreach(Control ctrl in MultiView1.Controls)
      {
            showControls(ctrl);
      }
}

private void showControls(Control ctrl)
{
      if(ctrl.Controls.Count>0)
      {
            foreach(Control ctrl1 in ctrl.Controls)
            {
                  Response.Write(ctrl1.GetType().ToString());
                  if(ctrl1 is CheckBox )
                  {
                        Response.Write("    It is CheckBox ");
                  }
                  Response.Write("<BR>");

                  showControls(ctrl1);
            }
      }

      else
      {
            Response.Write(ctrl.GetType().ToString());
            return;
      }
}
0

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

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

13 Experts available now in Live!

Get 1:1 Help Now