FindControlRecursive – Find a control in a hierarchy of controls

' Find a control in a hierarchy of controls' Example:'   Dim txtCtl As Control = FindControlRecursive(DataGrid1, "FirstNameTextBox")Function FindControlRecursive(ByVal ctrl As Control, _    ByVal id As String) As Control    ' Exit if this is the control we're looking for.    If ctrl.ID = id Then Return ctrl    ' Else, look in the hiearchy.    Dim childCtrl As Control    For Each childCtrl In ctrl.Controls        Dim resCtrl As Control = FindControlRecursive(childCtrl, id)        ' Exit if we've found the result        If Not resCtrl Is Nothing Then Return resCtrl    NextEnd Function' Note: This code is taken from Francesco Balena's' "Programming Microsoft Visual Basic .NET" - MS Press 2002, ISBN 0735613753' You can read a free chapter of the book at ' http://www.vb2themax.com/HtmlDoc.asp?Table=Books&ID=101000

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: