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?
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