2007/05/07

運用遞迴深度搜尋動態新增控制項

********************
// C#
public Control DepthFindControl(string ControlID, Control BaseControl)
{
Control result = BaseControl.FindControl(ControlID);
if (result == null)
{
foreach (Control ctl in Page.Controls)
{
if (ctl.Controls.Count > 0)
result = DepthFindControl(ControlID, ctl);
}
}
return result;
}

'Visual Basic
Public Function DepthFindControl(ControlID As String, BaseControl As Control) As Control
Dim result As Control = BaseControl.FindControl(ControlID);
If result Is Nothing Then
For Each ctl As Control In Page.Controls
If ctl.Controls.Count > 0 Then
result = DepthFindControl(ControlID, ctl)
End If
Next ctl
End If
Return result
End Function

********************


參考: 微軟MSDN

標籤:

0 Comments:

張貼留言

<< Home