Solved

Looping through controls

Posted on 2006-06-13
1
884 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to parse the string and split the sub directory names in asp.net 7 71
disable data migrations in visual studio 2017 4 41
asp.net mvc 2 32
How to repeat the data 4 30
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

679 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