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 8569725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:24:10+00:00 2026-06-11T18:24:10+00:00

In my user control, there is a gridview. I want to select/unselect all checkboxs

  • 0

In my user control, there is a gridview. I want to select/unselect all checkboxs inside the gridview using the header checkbox. So I implement it using jQuery.

function SelectAllCheckboxes(chk) {
    $('#<%=gridView.ClientID %> >tbody >tr >td >input:checkbox').attr('checked', chk.checked);
}

In my headertemplate of the gridview I put this one

<asp:CheckBox ID="chkHeader" runat="server"  OnClick="javascript:SelectAllCheckboxes(this);"/>

It works well.
But when another developer puts my user control in the aspx twice,
it does not work well.

Whenever I check the 1st or the 2nd Gridview’s header checkbox, only the 2nd GridViews’s checkboxes are check or uncheck.

It never check the first GridView’s checkboxes even when I check the 1st Gridview’s header checkbox.

What kind of modification do I need ?

Thanks in advance.

  • 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-06-11T18:24:12+00:00Added an answer on June 11, 2026 at 6:24 pm

    You could use closest() method:

    function SelectAllCheckboxes(chk) {
        $(chk).closest('table >tbody >tr >td >input:checkbox').attr('checked', chk.checked);
    }
    

    From jquery’s documentation: “Get the first element that matches the selector, beginning at the current element and progressing up through the DOM tree.”

    EDIT: I’m not pretty sure if it will work like that. If not, you could try:

    function SelectAllCheckboxes(chk) {
        $(chk).closest('table').find('>tbody >tr >td >input:checkbox').attr('checked', chk.checked);
    }
    

    Hope it helps.

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

Sidebar

Related Questions

I am written a User Control. in the User Control, There are Header and
I have listview control.There is an option to remove selected items.After the user removes
Is there a way to access page controls from user control . I have
I have a user control that takes a several seconds to load. Is there
Is there a winforms month-only picker control? I need to allow the user to
Lets say I have a complex user control (like GridView), and I extracted style
I have created a gridview for populating data, and some user control (TextBox) to
I am using an ASP.NET GridView control with a TemplateColumn which has a TextBox
When adding items to a gridview, I want the user to be able to
I have a nested gridview with 45 checkboxes. I want the user to be

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.