Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ...

how can select all check box using select All button.
Posted
Comments
P.Salini 6-Apr-12 0:43am    
In which technology you want to do it?
Arul R Ece 6-Apr-12 2:00am    
k salini ..,
i need in C #
Prasad_Kulkarni 6-Apr-12 0:44am    
Please tag your question with specific language, like c#, javascript etc.

Try this:
For C#:
C#
private void SelectAllCheckBoxControls(Control parent,bool checkedVal)
            {
            try
                {
                string strLeave=string.Empty;
                foreach (Control child in parent.Controls)
                    {
                    if (child.GetType().ToString().Equals("System.Web.UI.WebControls.CheckBox"))
                        {
                        CheckBox chk = (CheckBox)child;
                        chk.Checked=checkedVal;
                        }
                    }
                }
             catch(Exception exp)
                {
                throw new Exception("SelectAllCheckBoxControls  " + exp.Message);
                }
            }

For JavaScript:
C#
var checkboxes = document.getElementById( 'boxes' ).getElementsByTagName( 'input' );
for ( var i = 0; i < checkboxes.length; i++ )
{
    if ( checkboxes[i].type == 'checkbox' )
    {
        checkboxes[i].chcked = true;
    }
}
 
Share this answer
 
v2
useful for Windows as well as Asp.net Application.

Use CheckboxList control.
and use following code
foreach(ListItem lst in chklst.Items) {
lst.Selected = true;
}

here chklst is nothing but CheckboxList control

Hope, this code will be helpful for you.

Best Regards,
Anil Avhad(India)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900