迭代“MainContents”中的每个文本框控件?
我可以使用下面的代码迭代“MainContents”中的每个文本框控件。 Q1:有更短的路吗? (获取“MainContents”中的所有控件?)
For Each ctrl As Control In Page.Controls
For Each subctrl As Control In ctrl.Controls
For Each subctrlsub As Control In subctrl.Controls
If TypeOf subctrlsub Is System.Web.UI.WebControls.ContentPlaceHolder Then
If subctrlsub.ClientID = "MainContent" Then
For Each ct As Control In subctrlsub.Controls
If TypeOf ct Is System.Web.UI.WebControls.TextBox Then
For r As Short = 1 To 8
For c As Short = 1 To 6
.... (do something) ...
Next
Next
End If
Next
End If
End If
Next
Next
Next
I'm able to iterate each text box control in "MainContents" by using the code below.
Q1: Is there a shorter way? (to get all controls in "MainContents"?)
For Each ctrl As Control In Page.Controls
For Each subctrl As Control In ctrl.Controls
For Each subctrlsub As Control In subctrl.Controls
If TypeOf subctrlsub Is System.Web.UI.WebControls.ContentPlaceHolder Then
If subctrlsub.ClientID = "MainContent" Then
For Each ct As Control In subctrlsub.Controls
If TypeOf ct Is System.Web.UI.WebControls.TextBox Then
For r As Short = 1 To 8
For c As Short = 1 To 6
.... (do something) ...
Next
Next
End If
Next
End If
End If
Next
Next
Next
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将其从 C# 转换为 VB,请原谅潜在的错误。这称为递归。
I converted this from C# to VB, forgive the potential incorrectness. This is called Recursion.