2013-04-04 46 views
1

我想做的用户控件如下:“类型或命名空间名称找不到”在用户控件

foreach(Control c in this.Controls) 
{ 
    if(c is CheckBox) 
    { 
     // Do stuff here 
    } 
} 

但我得到的错误:

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?)

三江源指导。

+1

你看了错误消息System.Windows.Controls?它告诉你到底是什么问题。您需要导入对应于'Control'和'Checkbox'的2个DLL。 – tnw 2013-04-04 13:52:10

+0

您是否导入了'System.Windows.Forms.Control'? – Joetjah 2013-04-04 13:51:14

回答

8

您忘记了包含System.Web.UI.WebControlsSystem.Windows.Forms(取决于您正在开发的应用程序的类型)与using指令。

+0

感谢您的帮助! – saam 2013-04-04 13:54:43

+0

@saam如果这个工作,然后请标记为答案。 – 2013-04-04 13:55:33

+1

@PM我确定我会等7分钟后 – saam 2013-04-04 13:57:11

1

您需要添加System.Windows.Forms.dll。

它位于System.Windows.Forms命名空间的System.Windows.Forms.dll中。

3

您应该添加任何System.Windows.Forms的,或System.Web.UI.WebControls,或取决于你用什么技术

相关问题