Click here to Skip to main content
15,311,717 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Friends,

I am using VS 2013,Javascript.
I have a gridview with 4 checkbox.When I check on first checkbox,other 3 checkboxes are checked.But when I uncheck the first check box,other 3 checkboxes should be unchecked.But unchecking of 3 checkboxes are not coming .
<asp:CheckBox ID="chkInclude" runat="server" EnableViewState="true" >

What I have tried:

C#
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            CheckBox chkInclude = (CheckBox)e.Row.FindControl("chkInclude");
            CheckBox chkCreate = (CheckBox)e.Row.FindControl("chkCreate");
            CheckBox chkChange = (CheckBox)e.Row.FindControl("chkChange");
            CheckBox chkDelete = (CheckBox)e.Row.FindControl("chkDelete");

            chkInclude.Attributes.Add("OnClick", "checkAllCheckBoxTrue(document.getElementById('" + chkInclude.ClientID + "'),document.getElementById('" + chkCreate.ClientID + "'),document.getElementById('" + chkChange.ClientID + "'),document.getElementById('" + chkDelete.ClientID + "'),document.getElementById('" + GridView1.ClientID + "'))");
           

        }
    }<pre lang="Javascript"><pre>function checkAllCheckBoxTrue(viewid, createid, changeid, deleteid, grid) {
    
    for (i = 1; i < grid.rows.length; i++) {

           
        id1 = grid.rows[i].cells[3].childNodes[0];
       
        
        if (id1.checked = false)
        {
            
            createid = grid.rows[i].cells[4].childNodes[0]; // get
            changeid = grid.rows[i].cells[5].childNodes[0]; // get
            deleteid = grid.rows[i].cells[6].childNodes[0]; // get
            
            createid.checked = false;
            changeid.checked = false;
            deleteid.checked = false;

          
        }
        else if (id1.checked = true) {
          
            createid.checked = true;
            changeid.checked = true;
            deleteid.checked = true;

            createid.disabled = false;
            changeid.disabled = false;
            deleteid.disabled = false;
           
        }
    }
   
}
Posted
Updated 10-Jul-17 23:39pm
Comments
F-ES Sitecore 11-Jul-17 4:50am
   
if (id1.checked = false)
if (id1.checked = true)

Use "==" to compare, and "=" to assign. Change these to

if (id1.checked == false)
if (id1.checked == true)

There might be other issues in your code, I haven't tried it

Write the complete check handling as handler of the include checkbox.

In your function must must correct the comparison to "=="
   
I think you should simply do this, so that your are not using negative comparison. Also, notice that I have moved your code which is enabling check boxes before the code setting checkboxes to checked.

if (id1.checked)
{
createid.disabled = false;
changeid.disabled = false;
deleteid.disabled = false;

createid.checked = true;
changeid.checked = true;
deleteid.checked = true;

}
else
{
createid = grid.rows[i].cells[4].childNodes[0]; // get
changeid = grid.rows[i].cells[5].childNodes[0]; // get
deleteid = grid.rows[i].cells[6].childNodes[0]; // get

createid.checked = false;
changeid.checked = false;
deleteid.checked = false;
}
   
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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