2009-04-23 8 views

Répondre

1

Avez-vous essayé:

Me.Controls.Cast(Of Control) 

Sur intérêt, pourquoi avez-vous besoin comme IQueryable? N'est-ce pas IEnumerable<T> assez pour vous? (C'est le résultat de Cast.)

Le problème avec l'appel de AsQueryable est que la collection de contrôles n'implémente pas IEnumerable<T>, juste IEnumerable.

1

Aussi, ne pas oublier que les contrôles peuvent être imbriquées, et juste demander la page pour ses commandes ne vous parler des enfants directs, mais il ne sera pas vous dire au sujet des contrôles dans ces contrôles:

Locate the web forms controls on a page by walking the Controls Collection

This example finds only the controls contained in the Page object and the controls that are direct children of the page. It does not find text boxes that are children of a control that is in turn a child of the page. For example, if you added a Panel control to page, the Panel control would be a child of the HtmlForm control contained by the Page, and it would be found in this example. However, if you then added a TextBox control into the Panel control, the TextBox control text would not be displayed by the example, because it is not a child of the page or of a control that is a child of the page. A more practical application of walking the controls this way would be to create a recursive method that can be called to walk the Controls collection of each control as it is encountered. However, for clarity, the example below is not created as a recursive function.

Questions connexes