Solved

How to identify what type a control is

Posted on 2004-10-17
2
252 Views
Last Modified: 2011-09-20
In the following piece of program, how could I identify which are combo boxes, for example?

foreach (Control ctl in Controls)
{
   if ( ***a combo box is found*** )
      ctl.Text = "";
}
0
Comment
Question by:Alberto071397
  • 2
2 Comments
 
LVL 6

Accepted Solution

by:
ryerras earned 125 total points
ID: 12334724
ctl is DropDownList
0
 
LVL 6

Expert Comment

by:ryerras
ID: 12334757
But the code you posted takes you no where. By default, the Page.Controls has the WebForm as one control. It wouldnt be able to find controls on the WebForm. For that you need to loop inside, try as follows
foreach (Control ctl in Controls)
 {
      if(ctl is DropDownList)
             Response.Write("Text : "+ ctl.Text);
      else if (ctl.HasControls())
        {
            foreach (Control ctl in ctrl.Controls)
              {
                if(ctl is DropDownList)
                   Response.Write("Text: "+ ctl.Text);
            }
          }
}
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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