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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:36:49+00:00 2026-05-26T23:36:49+00:00

I am using visual studio 2005 c#, and doing server side coding. I have

  • 0

I am using visual studio 2005 c#, and doing server side coding.

I have a checkbox template in my gridview. I have tried to assign a CheckAllCB button outside the gridview, so that whenCheckAllCB is clicked, the list of checkboxes in the item template will be checked.
However, it does not work and I am not able to spot the mistake.
Below is my code for my CheckAllCB button:

protected void CheckAllCB_CheckedChanged(object sender, EventArgs e)
{
    CheckBox chk = (CheckBox)GridView1.HeaderRow.FindControl("CheckAll");
    if (chk.Checked)
    {
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            CheckBox chkrow = (CheckBox)GridView1.Rows[i].FindControl("UserSelector");
            chkrow.Checked = true;
        }

    }
    else
    {
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            CheckBox chkrow = (CheckBox)GridView1.Rows[i].FindControl("UserSelector");
            chkrow.Checked = false;
        }
    }
}

(SOLVED)


Thus I tried using a checkbox checkchange in the header template. However, when the checkbox CheckAll in header template is check changed, nothing happens in the checkboxes in the itemtemplate.

Below is my code for CheckAllCB in header template

private void ToggleCheckState(bool checkState)
{
    // Iterate through the Products.Rows property
    foreach (GridViewRow row in GridView1.Rows)
    {
        // Access the CheckBox
        CheckBox cb = (CheckBox)row.FindControl("UserSelector");
        if (cb != null)
            cb.Checked = checkState;
    }
}
protected void CheckAll_Click(object sender, EventArgs e)
{
    ToggleCheckState(true);
}
protected void UncheckAll_Click(object sender, EventArgs e)
{
    ToggleCheckState(false);
}

Anyone can help me identify the mistake I did in my method? Thank you


UserSelection item template:
enter image description here

CheckAllCB header template:
enter image description here


Added source code for GridView:

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" ondatabound="gv_DataBound" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
    <Columns>
                     <asp:TemplateField>
                     <HeaderTemplate>
                         <asp:CheckBox ID="CheckAllCB" runat="server" OnCheckedChanged="CheckAllCB_CheckedChanged" />
  </HeaderTemplate>
                        <ItemTemplate>

                          <asp:CheckBox ID="UserSelection" OnCheckedChanged="UserSelector_CheckedChanged" runat="server" />

                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
</asp:GridView>
  • 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-26T23:36:49+00:00Added an answer on May 26, 2026 at 11:36 pm

    The problem is that the checkbox is declared as UserSelection in the page, but you are looking for UserSelector in codebehind.

    Also, the header is declared as CheckAllCB in the page, but you are looking for CheckAll in the codebehind.

    You need to change one or the other so that the names match.

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

Sidebar

Related Questions

I am using Visual Studio 2005, Sql Server 2005, C#, ADO.NET. We have a
(Using Visual Studio 2005 / .NET 2.0) I have a DataSet which is being
I am using Visual Studio 2005 with Team Foundation Server. When I right click
I'm using Visual Studio 2005. I have a program written in C#. When I
I am using Visual studio 2005 for my development. I am doing a smart
Using Visual Studio 2005 I have list of class files, when i try to
Using Visual Studio 2005 Language: c# A new to c# I have software, the
Does anyone have experience using makefiles for Visual Studio C++ builds (under VS 2005)
Using Visual Studio 2005 - C# 2.0, System.Net.WebClient.UploadData(Uri address, byte[] data) Windows Server 2003
Using Visual Studio 2005 with the latest Service Pack. I have a managed C++

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.