Reputation: 491
I want to do the following in a UserControl:
foreach(Control c in this.Controls)
{
if(c is CheckBox)
{
// Do stuff here
}
}
But I get the the error:
Error 1 The type or namespace name 'Control' could not be found (are you missing a using directive or an assembly reference?)
Error 2 The type or namespace name 'CheckBox' could not be found (are you missing a using directive or an assembly reference?)
Thankyou for the guidance.
Upvotes: 1
Views: 4263
Reputation: 8937
You should add either System.Windows.Forms, or System.Web.UI.WebControls, or System.Windows.Controls depending on what technology you use
Upvotes: 3
Reputation: 98868
You need to add System.Windows.Forms
namespace which includes System.Windows.Forms.dll for Control
class.
Also you need to add System.Web.UI.WebControls
namespace which includes System.Web.dll for Checkbox
class.
Like;
using System.Windows.Forms;
using System.Web.UI.WebControls;
Upvotes: 2
Reputation: 10171
you need to add System.Windows.Forms.dll.
It's located in System.Windows.Forms.dll
in the System.Windows.Forms namespace.
Upvotes: 1
Reputation: 56726
You forgot to include either System.Web.UI.WebControls
or System.Windows.Forms
(depending on the type of the app you are developing) with using
directive.
Upvotes: 8