3

Example :

foreach (CheckBox chb in myPanel.Controls.OfType<CheckBox>().Where(p => p.Checked)))

cycle only first-level checkbox. How if I have second-level checkbox? Like inside another HtmlGenericControl (that is, at first-level, inside myPanel) ?

markzzz
  • 47,390
  • 120
  • 299
  • 507

2 Answers2

3

https://stackoverflow.com/a/253962/232574

(How do I make this a "Linked" question for this question?)

EDIT: Did that happen automatically?

Community
  • 1
  • 1
Nick Strupat
  • 4,928
  • 4
  • 44
  • 56
2

Use a recursive method. Move myPanel to the method parameters and add a call inside the foreach loop that will call the same method and myPanel parameter gets the checkbox.

Amiram Korach
  • 13,056
  • 3
  • 28
  • 30
  • Uhm...it depends! Maybe I have 2 checkbox at first-level, than a div with one, than a empty span, and so on. Can I get ALL CheckBox inside a Panel? Seems strange... – markzzz Jul 09 '12 at 14:28
  • This shouldn't matter. If a control is a div then ignore it and just call the same method with the div to get its check boxes. If the control given to the method has no child controls then just return from this call. – Amiram Korach Jul 09 '12 at 14:31