Recursively extract dynamically created controls in a repeater, Part II [closed]
To be fair, this is a part two follow up to Using C# to recursively get a collection of controls from a controlcollection - and rather than heap another question onto the old one, I created a new one. Here is the code that I'm using:
private void GetControlList<T>(ControlCollection controlCollection, ref List<T> resultCollection) where T : Control
{
foreach (Control control in controlCollection)
{
if (control.HasControls())
GetControlList(control.Controls, ref resultCollection);
else if (control is T)
resultCollection.Add((T)control);
}
}
and is involked like this when the form is submitted
List<CheckBox> checkboxes = new List<CheckBox>();
GetControlList(RepeaterCapability.Controls, ref checkboxes);
The problem is that I don't get any results when I clearly added several during the repeater OnItemDataBound event. Any ideas?
Have you checked the Repeater.Items property?
REsolved ... PEBKAC
精彩评论