Solved

Looping through controls

Posted on 2006-06-13
1
877 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

790 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