Hakoo 14 Junior Poster

Hello all,
I have taken CheckBox List and elements are ,

  • Insert
  • Edit
  • Delete
  • View
  • All

Now, I want functionality like if I select "All", rest of 4 should be selected and if I deselect it all rest should be deselected. For this I have used this code :

protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        
        
            if (CheckBoxList1.Items[4].Selected)
            {
                for (int i = 0; i < CheckBoxList1.Items.Count - 1; i++)
                    CheckBoxList1.Items[i].Selected = true;

            }
            else if (!CheckBoxList1.Items[4].Selected)
            {

                for (int i = 0; i < CheckBoxList1.Items.Count - 1; i++)
                {

                    CheckBoxList1.Items[i].Selected = false;

                }

            }
        
    }

This is working fine for particularly for "All" checkbox. but when I am trying to select except all, its not allowing me to select rest. Its going into "else if". Is it possible for what I am looking for?

Or , I suppose to take seperate CheckBox for All selection?

Thanking You.
Hakoo Desai

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.