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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:17:59+00:00 2026-05-30T21:17:59+00:00

I have a CheckBox and a CheckBox list on my web page. If the

  • 0

I have a CheckBox and a CheckBox list on my web page.
If the CheckBox is selected, all the CheckBoxes in the CheckBoxList should get selected, and if the CheckBox is unchecked, similarly all the CheckBoxes in the CheckBox should get deselected (unchecked).

.aspx code

<asp:CheckBoxList ID="CheckBoxList1" runat="server" 
            RepeatDirection="Horizontal" RepeatLayout="Flow">
            <asp:ListItem>Item A</asp:ListItem>
            <asp:ListItem>Item B</asp:ListItem>
            <asp:ListItem>Item C</asp:ListItem>
            <asp:ListItem Selected="True">Item D</asp:ListItem>
            <asp:ListItem>Item E</asp:ListItem>
            <asp:ListItem>Item F</asp:ListItem>
            <asp:ListItem>Item G</asp:ListItem>
        </asp:CheckBoxList>
<asp:CheckBox ID="allChkBox" Text="Select all" runat="server" 
                oncheckedchanged="allChkBox_CheckedChanged" />

I tried by doing somehting like this, but it didb’t work:

bool prevSelection = false;
protected void allChkBox_CheckedChanged(object sender, EventArgs e)
    {
if (!prevSelection)
        {
            foreach (ListItem chkitem in CheckBoxList1.Items)
            {
                chkitem.Selected = true;
            }
        }
        else
        {
            foreach (ListItem chkitem in CheckBoxList1.Items)
            {
                chkitem.Selected = false;
            }
        }
        prevSelection = !prevSelection;
}
  • 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-30T21:18:00+00:00Added an answer on May 30, 2026 at 9:18 pm

    I prefer to use client script for something like this so your page doesnt have to do a postback

    If that is a possibility try firing a javascript function on click to do the looping and selecting … something like

    <script type="text/javascript">
    checked=false;
    function checkedAll (frm1) {
        var aa= document.getElementById('frm1');
         if (checked == false)
              {
               checked = true
              }
            else
              {
              checked = false
              }
        for (var i =0; i < aa.elements.length; i++) 
        {
               if(aa.elements[i].type == 'checkbox') { 
                 aa.elements[i].checked = checked;
               }
        }
     }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three different checkbox list on my web page. I want to have
We have an ASP.Net page that uses a checkbox to toggle between a list
Ok so I have a checkbox list with n checkboxes. Everytime I check a
I have used ModalpopupExtender control in my web page. I have checkbox for selectall
I have a checkbox list control on my asp.net web form that I am
I have a checkedlistbox in asp.net web form page as : <asp:CheckBoxList ID=TagListCheckBox runat=server
In ASP.NET, I have collected a list of selected items from a checkbox in
I have a CheckBox list and I want to get the number of items
I have a checkbox list that isn't updating on the looping through it. <asp:CheckBoxList
I have a web form with some TextBoxes and CheckBoxList . I want to

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.