0
我需要更改我的aspx页面中许多控件的可见性。通过引用查找aspx页面中的所有控件
我发现了几个方法来得到这样this one
的控制,但我不能设置值,此控制,因为它们是由VAL过去了,我不知道我是怎么可以添加裁判关键词在这种情况下。
我需要更改我的aspx页面中许多控件的可见性。通过引用查找aspx页面中的所有控件
我发现了几个方法来得到这样this one
的控制,但我不能设置值,此控制,因为它们是由VAL过去了,我不知道我是怎么可以添加裁判关键词在这种情况下。
试试这个link,它应该工作正常。顺便说一句,控制是一种参考类型而不是一种值类型。
从你的问题example,这样做:
IEnumerable<Control> EnumerateControlsRecursive(Control parent)
{
foreach (Control child in parent.Controls)
{
yield return child;
foreach (Control descendant in EnumerateControlsRecursive(child))
yield return descendant;
}
}
用法:
foreach (Control c in EnumerateControlsRecursive(Page))
{
if(c is TextBox)
{
var theTextBox = c as TextBox;
theTextBox.Visible = false;
}
if(c is Label)
{
var theLabel = c as Label;
theLabel.Visible = false;
}
...
}
'Control'是引用类型,这样的引用传递。您应该没有问题设置可见性属性。 – Magnus