Solved

Looping through controls

Posted on 2006-06-13
1
871 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
ID: 16899698
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

832 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