''' <summary> ''' 遞迴尋找指定 ID 的控制項。 ''' </summary> ''' <param name="Parent">父代控制項。</param> ''' <param name="ID">欲尋找的控制項識別 ID。</param> ''' <returns>回傳 ID 符合的控制項,若未找到則傳回 Nothing。</returns> Public Function FindControlEx() Function FindControlEx(ByVal Parent As System.Web.UI.Control, ByVal ID As String) As System.Web.UI.Control Dim oCtrl As System.Web.UI.Control = Nothing Dim oChildCtrl As System.Web.UI.Control = Nothing '先使用 FindControl 去尋找指定的子控制項 oCtrl = Parent.FindControl(ID) '若尋找不到則往下層遞迴方式去尋找() If oCtrl Is Nothing Then For Each oChildCtrl In Parent.Controls '以遞迴方式呼叫原函式 oCtrl = FindControlEx(oChildCtrl, ID) '若有尋找到指定控制項則離開迴圈 If oCtrl IsNot Nothing Then Exit For Next End If Return oCtrl End Function