循环用户控件的正确逻辑
我有一个动态网页,可以多次加载用户控件,包括根据需要多次加载用户控件。用户控件内有四个控件:标题标签、Repeater、Placeholder,Repeater 内有一个 AjaxControlToolkit Rating 控件。
该结构可能如下所示:
Webpage
Placeholder
UserControl (repeater hidden, no data)
Placeholder - [UserControl]
UserControl
Repeater
RepeaterItem - [RatingControl]
RepeaterItem - [RatingControl]
Placeholder - [UserControl]
UserControl (placeholder hidden, no data)
Repeater
RepeaterItem - [RatingControl]
RepeaterItem - [RatingControl]
UserControl
Repeater
RepeaterItem - [RatingControl]
RepeaterItem - [RatingControl]
Placeholder - [UserControl]
UserControl (placeholder hidden, no data)
Repeater
RepeaterItem - [RatingControl]
这是我的递归方法:
Protected Sub Get_Ratings(ByVal ctl As Control, ByVal grouptotal As Integer)
If TypeOf ctl Is PerformanceEvaluationSubcontractorControl Then
Dim pesctl As Control
For Each pesctl In ctl.Controls
If TypeOf pesctl Is PerformanceEvaluationSubcontractorControl Then
Me.Get_Ratings(pesctl, grouptotal)
ElseIf pesctl.Controls.Count > 0 Then
Dim spesctl As Control
For Each spesctl In pesctl.Controls
If TypeOf spesctl Is Repeater Then
Dim rptctl As Control
For Each rptctl In spesctl.Controls
Me.Get_Ratings(pesctl, grouptotal)
Next
End If
If TypeOf spesctl Is PlaceHolder Then
Dim plhctl As Control
For Each plhctl In spesctl.Controls
Me.Get_Ratings(plhctl, grouptotal)
Next
End If
Next
ElseIf TypeOf pesctl Is AjaxControlToolkit.Rating Then
Dim ajrating As AjaxControlToolkit.Rating = pesctl
grouptotal = grouptotal + ajrating.CurrentRating
End If
Next
ElseIf ctl.Controls.Count > 0 Then
Dim sctl As Control
For Each sctl In ctl.Controls
Me.Get_Ratings(sctl, grouptotal)
Next
End If
End Sub
我的问题是,如何有效地循环这种类型的结构以找到评级控件?
I have a dynamic webpage that loads a user control multiple times, including loading the user control within itself as many times as needed. Within the user control there are four controls: Title Label, Repeater, Placeholder and within Repeater a AjaxControlToolkit Rating control.
The structure can look like the following:
Webpage
Placeholder
UserControl (repeater hidden, no data)
Placeholder - [UserControl]
UserControl
Repeater
RepeaterItem - [RatingControl]
RepeaterItem - [RatingControl]
Placeholder - [UserControl]
UserControl (placeholder hidden, no data)
Repeater
RepeaterItem - [RatingControl]
RepeaterItem - [RatingControl]
UserControl
Repeater
RepeaterItem - [RatingControl]
RepeaterItem - [RatingControl]
Placeholder - [UserControl]
UserControl (placeholder hidden, no data)
Repeater
RepeaterItem - [RatingControl]
Here is my recursive method:
Protected Sub Get_Ratings(ByVal ctl As Control, ByVal grouptotal As Integer)
If TypeOf ctl Is PerformanceEvaluationSubcontractorControl Then
Dim pesctl As Control
For Each pesctl In ctl.Controls
If TypeOf pesctl Is PerformanceEvaluationSubcontractorControl Then
Me.Get_Ratings(pesctl, grouptotal)
ElseIf pesctl.Controls.Count > 0 Then
Dim spesctl As Control
For Each spesctl In pesctl.Controls
If TypeOf spesctl Is Repeater Then
Dim rptctl As Control
For Each rptctl In spesctl.Controls
Me.Get_Ratings(pesctl, grouptotal)
Next
End If
If TypeOf spesctl Is PlaceHolder Then
Dim plhctl As Control
For Each plhctl In spesctl.Controls
Me.Get_Ratings(plhctl, grouptotal)
Next
End If
Next
ElseIf TypeOf pesctl Is AjaxControlToolkit.Rating Then
Dim ajrating As AjaxControlToolkit.Rating = pesctl
grouptotal = grouptotal + ajrating.CurrentRating
End If
Next
ElseIf ctl.Controls.Count > 0 Then
Dim sctl As Control
For Each sctl In ctl.Controls
Me.Get_Ratings(sctl, grouptotal)
Next
End If
End Sub
My question is, how do I efficiently loop through this type of structure to find the rating controls?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
抱歉,我的 VB.NET 不是那么好,但是递归函数不会类似于:
你不能做一个求和吗:
如果语法有问题,请告诉我,我通常不会这样做网络
Sorry, my VB.NET isn't all that great, but wouldn't a recursive function look similar to:
Couldn't you then do a summation:
If the syntax is way off, let me know, I don't normally do VB.NET
下面的代码非常适合我的需求。我没有测试 AjaxControlToolkit.Rating 类型。
调用子程序
使用Here is the sub
The code below works perfectly for my needs. I did not test the AjaxControlToolkit.Rating type.
Call the sub with
Here is the sub