Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 66211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:04:04+00:00 2026-05-10T19:04:04+00:00

If I wanted to find checked check boxes on an ASP.NET page I could

  • 0

If I wanted to find checked check boxes on an ASP.NET page I could use the following LINQ query.

var checkBoxes = this.Controls                      .OfType<CheckBox>()                      .TakeWhile<CheckBox>(cb => cb.Checked); 

That works fine if the checkboxes are nested in the current control collection, but I’d like to know how to extend the search by drilling down into the control collections of the top-level controls.

The question was asked here:

Finding controls that use a certain interface in ASP.NET

And received non-LINQ answers, I already have my own version of a recursive control search on type and ID as extension methods, but I just wondered how easy this is to do in LINQ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T19:04:04+00:00Added an answer on May 10, 2026 at 7:04 pm

    Take the type/ID checking out of the recursion, so just have a ‘give me all the controls, recursively’ method, e.g.

    public static IEnumerable<Control> GetAllControls(this Control parent) {     foreach (Control control in parent.Controls)     {         yield return control;         foreach(Control descendant in control.GetAllControls())         {             yield return descendant;         }     } } 

    That’s somewhat inefficient (in terms of creating lots of iterators) but I doubt that you’ll have a very deep tree.

    You can then write your original query as:

    var checkBoxes = this.GetAllControls()                      .OfType<CheckBox>()                      .TakeWhile<CheckBox>(cb => cb.Checked); 

    (EDIT: Changed AllControls to GetAllControls and use it properly as a method.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know I could use PHP to do this, but wanted to find out
Hey I just wanted to find out the working of the following script as
I wanted to use find to find every file in a directory that starts
I wanted to find out what is the best practices approach to a query
Let's say I wanted to find the last div on the page and do
I wanted to find a way to upload a single file*, in the background,
I decided to learn concurrency and wanted to find out in how many ways
I am converting fortran code to C++ and wanted to find a right option
This is a common scenario, but i wanted to find out which way is
I'm not sure if this is possible at all, but wanted to find out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.