VB.NET中怎样取到Panel里面的子控件的值?
大家好,遇到一个问题!在panel里面new了一个lable,现在要取到lable的属性给他赋值.这样可以取到
Dim lbl As Label = Me.panel.Controls("lableName")
lbl.Text = "Hello"
那么如果在 大panel里面new了一个新Panel1,在新panel1里面又new了一个lable,问题怎样才能取到他的子控件lable的属性,给他赋值呢?求具体代码送分!谢谢!! vb.net?子控件?赋值
[解决办法]
在new新Panel1时给Panel1.Name=“Panel1”
然后
Dim lbl As Label = Me.panel.Controls("Panel1").Controls("lableName")
lbl.Text = "Hello"
总之,你如果知道你创建的控件名称,都可以通过Controls(控件名称)一层层的往下找,如果不知道控件名称,就用for each遍历
For Each c as control in Me.Panel.Controls
if TypeOf(c) is Panel then
For Each l as control in c.Controls
if TypeOf(l) is Label then
l.Text="Hello"
exit for
end if
next
end if
next
[解决办法]
可以使用:FindControl("你new时的id");来得到lable对象。
[解决办法]
楼上的解答都可以.
Dim c As Control() = Me.Panel.Controls.Find("lblName", True)
For Each con As Control In c
If TypeOf (con) Is Label Then
con.Text = "Hello"
Exit For
End If
Next