2010-12-01 13 views
0

以下のコードを使用して、 "MainContents"の各テキストボックスコントロールを反復することができます。 Q1:短い方法はありますか? (「メインコンテンツ」ですべてのコントロールを取得するには?)"MainContents"の各テキストボックスコントロールを繰り返しますか?

For Each ctrl As Control In Page.Controls 
     For Each subctrl As Control In ctrl.Controls 
      For Each subctrlsub As Control In subctrl.Controls 
       If TypeOf subctrlsub Is System.Web.UI.WebControls.ContentPlaceHolder Then 
        If subctrlsub.ClientID = "MainContent" Then 
         For Each ct As Control In subctrlsub.Controls 
          If TypeOf ct Is System.Web.UI.WebControls.TextBox Then 
           For r As Short = 1 To 8 
            For c As Short = 1 To 6 
             .... (do something) ... 
            Next 
           Next 
          End If 
         Next 
        End If 
       End If 
      Next 
     Next 
    Next 

答えて

0

私は、潜在的な不正確を許し、C#のからVBにこれを変換します。これは再帰と呼ばれます。

Protected Sub DoSomething(ctrl As Control) 
    For Each c As Control In ctrl.Controls 
     If TypeOf c Is ContentPlaceHolder Then 
      If c.ClientID = "MainContent" Then 
          // Do your stuff 
      End If 
     End If 

     If c.Controls.Count > 0 Then 
      DoSomething(c) 
     End If 
    Next 
End Sub 
関連する問題