Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Grid is look like this..

col0         col1
checkbox     123
checkbox     234
empty row
checkbox     12

now what i'm try to do is i want to select All checkBox's and DeselectAll how to do...


i'm trying in the following way...

JavaScript
function CheckAll(oCheckbox) {
    var gdDocument = document.getElementById("<%=gdDocument.ClientID %>");

    for (i = 1; i < gdDocument.rows.length; i++) {
        gdDocument.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = oCheckbox.checked;
     }

}

C#
<HeaderTemplate>
     <input id="chkSelect" type="checkbox" onclick="CheckAll(this)" runat="server" />
 </HeaderTemplate>
 <ItemTemplate>
     <asp:CheckBox ID="chkSelect" runat="server"  />
 </ItemTemplate>


but for this code is working for each & everyrow have a record this code is working fine , but whenever the row checkbox is not visible ( false). In that case , from there onwords the checkbox's are not selected.

can anyone help me to resolve this issue...
Posted
Updated 29-Jan-13 19:01pm
v2
Comments
vinodkumarnie 30-Jan-13 1:38am    
Handle checkbox not visible case in your code... If the checkbox is not visible skip that loop and go for next loop.

1 solution

try the following code, its working fine for me

C#
protected void chekSelectALL_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox chkA = GridView1.HeaderRow.FindControl("chekSelectALL") as CheckBox;
        foreach (GridViewRow gv in GridView1.Rows)
        {
            CheckBox chkS = gv.FindControl("chekSelect") as CheckBox;
            if (chkA.Checked)
            {
                chkS.Checked = true;
            }
            else
            {
                chkS.Checked = false;
            }
        }
    }
 
Share this answer
 
Comments
[no name] 30-Jan-13 2:40am    
+5
AshishChaudha 30-Jan-13 3:21am    
Thanks sisir
[no name] 30-Jan-13 7:48am    
yw

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