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

  • Home
  • SEARCH
  • 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 949995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:29:37+00:00 2026-05-15T23:29:37+00:00

foreach (GridViewRow row in gridView.Rows) { // Access the CheckBox CheckBox cb = (CheckBox)row.FindControl(SuburbSelector);

  • 0
foreach (GridViewRow row in gridView.Rows)
{ // Access the CheckBox 
    CheckBox cb = (CheckBox)row.FindControl("SuburbSelector");
    if (cb.Checked)
    {
        //do something;
    }
}

I tried the following and got error

Linq:

var Str = SuburbGridView.Rows.Cast<GridViewRow>().Where(r=>(CheckBox)r.FindControl("SuburbSelector")==checked);

Error:

Delegate ‘System.Func < System.Web.UI.WebControls.GridViewRow,int,bool>’ does not take 1 arguments

Many thanks

  • 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. Editorial Team
    Editorial Team
    2026-05-15T23:29:38+00:00Added an answer on May 15, 2026 at 11:29 pm

    Linq doesn’t seem to have a good “each” aggregate. There is Aggregate(), which I don’t like if I’m not actually accumulating anything, since the accumulator value is essentially thrown away. I don’t think there’s anything equivalent to List<T>.ForEach(), and it’s a shame. If you’re using C# 4.0, and don’t mind processing in parallel, you could use .AsParallel().ForAll(). So anyway, here’s a few ways to do what you want:

    Using List.ForEach():

    SuburbGridView.Rows.Cast<GridViewRow>().Where(
        r => ((CheckBox)r.FindControl("SuburbSelector")).Checked).ToList().ForEach(row =>
    {
        Response.Write(row.ID);
        // Do something
    });
    

    And using Parallel Linq:

    SuburbGridView.Rows.Cast<GridViewRow>().Where(
        r => ((CheckBox)r.FindControl("SuburbSelector")).Checked).AsParallel().ForAll(row =>
    {
        Response.Write(row.ID);
        // Do something
    });
    

    I’m just getting the hang of this LINQ stuff myself. I love it.

    By the way, you were just missing an extra pair of ()‘s around your cast. FindControl() returns a System.Web.UI.Control, and you have to cast it to CheckBox to access the Checked property. You can’t do it like this:

    // Doesn't work
    (CheckBox)row.FindControl("someCheckbox").Checked
    

    That doesn’t work because of the order of operations. The .Checked is evaluated before the cast to CheckBox, which means you’re trying to access a CheckBox property of Control, and it doesn’t exist. The extra pair of parens fixes that.

    // Works
    ((CheckBox)row.FindControl("someCheckbox")).Checked
    

    And one last thing, you don’t need to do == true in your comparison. Checked is already a boolean value. If you like it there for clarity (some people do), then by all means keep it. It’s not considered bad practice or anything, it’s just a matter of preference.

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

Sidebar

Related Questions

foreach (GridViewRow row in GridView1.Rows) { var chk = row.FindControl(myCheckBox) as CheckBox; if (chk.Checked)
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
string total; int totalmarks = 0; foreach (GridViewRow row in GridView1.Rows) { int rowcount
public DataTable ExcelToDatatable_dt1 { get { foreach (GridViewRow rowItem in GridView1.Rows) { CheckBox chk;
I have a code: foreach (GridViewRow dr in gvCategories.Rows)<br/> { <br/> if (dr.Cells[0].Text ==
In this code fragment foreach (var row in grid.Rows) { } the type of
Hai I am using the following code to access columns in a row but
I've got a gridview (asp.net) with a checkbox and a radiobuttonlist. Above this gridview
I add all row CheckBox in my Gridview helping with this article . Here
I've got a gridview bound to an ObjectDataSource including a checkbox to select an

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.