gpt4 book ai didi

c# - 无效的转换异常 C# ASP.Net

转载 作者:行者123 更新时间:2023-11-30 13:59:43 25 4
gpt4 key购买 nike

foreach(Label l in Controls)    // setting all labels' s visbility  on page to true
l.Visible =true;

但是在运行时,出现以下错误

无法将“ASP.admin_master”类型的对象转换为类型“System.Web.UI.WebControls.Label”。

最佳答案

如果其中一个控件不是标签类型,您将收到该错误。

你可以试试:

foreach(Label l in Controls.OfType<Label>())
{
l.Visible = true;
}

关于c# - 无效的转换异常 C# ASP.Net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12660117/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com