我这么写
- VB.NET code
For Each Content As Content In Panel1.Controls Content.GetType() Next
错误为
无法将类型为“System.Web.UI.LiteralControl”的对象强制转换为类型“System.Web.UI.WebControls.Content”。
何解?
------解决方案--------------------------------------------------------
你总要判断一下 Content 是不是你要的类型吧,否则出错就很正常了
------解决方案--------------------------------------------------------
foreach (Control cl in Panel1.Controls)
{
}
------解决方案--------------------------------------------------------
- C# code
For Each cc As Control In Panel1.Controls cc.GetType() Next
------解决方案--------------------------------------------------------
For Each ctl as Control In Panel1.Controls
If ctl.GetType().ToString() = "System.Web.UI.WebControls.Content" Then
End If
Next