当前位置:编程学习 > C#/ASP.NET >>

新人!关于怎样循环应用控件!

我自己定义了5个textbox控件(textbox1,textbox2。。。。。。textbox5)
现在想用循环for 给5个控件.text赋值(值为数组a(1)...a(5)

我是这样用的 
for n=1 to 5
   "textbox"&n.text=a(1).tostring
next
可是比如n=1 "textbox"&n不能指定textbox1控件,它认为是一个字符串了,不是控件名!
--------------------编程问答-------------------- Me.Controls("textbox" & n).text=a(1).tostring --------------------编程问答-------------------- 数组下标从0开始吧
Me.Controls("textbox" & n).text=a(n-1).tostring --------------------编程问答-------------------- 参考 C# 动态添加控件及事件的方法 --------------------编程问答-------------------- 放到一个groupbox里
For Each thisControl As System.Windows.Forms.Control In Me.GroupBox_TxtBox.Controls
                  thisControl.txt=a(1).tostring
Next thisControl

如果想排除里面的LABEL控件,加个判断
 If thisControl.GetType.Name <> "Label" Then
          thisControl.Text = a(1).tostring
 End If
补充:.NET技术 ,  VB.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,