You must Sign In to post a response.
  • Category: JQuery

    SelectAll checkbox not checked

    I have a grid in which i have a "Sselect" checkbox as a column in the grid as below

    <input type="checkbox" class="checkClass" name="SelectAllName" value="Select" id="selectAll" onchange="selectall()" />

    And the rows in the grid are dynamic where i have checkboxes in each row as below:

    <%=Html.CheckBox(string.Format("TestDetails[{0}].Delete", count), Model.TestDetails[count].Delete, new { @class = "checkClass" })%>

    My selectall function is as below:

    function selectall() {
    $('#selectAll').click(function (event) {
    if (this.checked) {
    $('.checkClass').each(function () {
    this.checked = true;
    });
    } else {
    $('.checkClass').each(function () {
    this.checked = false;
    });
    }
    });
    }

    Issue: When i click the "Select" checkbox in the grid column, all the checkboxes in all the rows are checked but the "Select" checkbox is not checked. Please help me to solve the issue
  • #755515
    Hi,

    try this below code.

    $('#chkSelectAll').click(
    function () {
    // if check all is checked, all checkboxes are checked
    // if check all is unchecked, all checkboxes are cleared

    if ($('#chkSelectAll').is(':checked')) {
    $('input:checkbox[name$=chkSelect]').each(
    function () {
    $(this).attr('checked', 'checked');
    });
    }
    else {
    $('input:checkbox[name$=chkSelect]').each(
    function () {
    $(this).removeAttr('checked');
    });
    }
    });

    Regards,
    Kalandiyur Subramanian Mohan
    www.mohanks.com

  • #755521
    Thanks Mohan but .attr didn't work in 1.3.2 .js version so i used the below code to make it work:

    function selectAll() {
    $('#selectAll').click(function (event) {
    if (this.checked) {
    $('.checkClass').each(function () {
    this.checked = true;
    });
    } else {
    $('.checkClass').each(function () {
    this.checked = false;
    });
    } event.stopImmediatePropagation();//This event helped me to retain the check in the parent checkbox
    });
    }

  • #755533
    Hi,

    Use below sample code.


    < script type="text/Javascript" >

    function Check(parentChk,container)
    {
    var elements = document.getElementsByTagName("INPUT");
    for(i=0; i
    {
    if(parentChk.checked == true)
    {
    if( IsCheckBox(elements[i]) && IsMatch(elements[i].id,container))
    {
    elements[i].checked = true;
    }
    }
    else
    {
    if( IsCheckBox(elements[i]) && IsMatch(elements[i].id,container))
    {
    elements[i].checked = false;
    }
    }
    }
    }
    < script>


    <asp:TemplateField >
    <HeaderTemplate>
    <input id="HchkSelect" type="checkbox" onclick="javascript:Check(this,'GV');" />
    </HeaderTemplate>
    <ItemTemplate>
    <asp:CheckBox ID="chkSelect" runat="server" />
    </ItemTemplate>
    <ItemStyle HorizontalAlign="center" />
    </asp:TemplateField>



    Hope this will helpful to you to clear the issue.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #755578
    Check this sample code.



    protected void chkboxSelectAll_CheckedChanged(object sender, EventArgs e)
    {
    CheckBox ChkHeader = (CheckBox)GridVwHeaderChckbox.HeaderRow.FindControl("chkboxSelectAll");
    foreach (GridViewRow row in GridVwHeaderChckbox.Rows)
    {
    CheckBox ChkBoxRows = (CheckBox)row.FindControl("chkmain");
    if (ChkHeader.Checked == true)
    {
    ChkBoxRows.Checked = true;
    }
    else
    {
    ChkBoxRows.Checked = false;
    }
    }
    }

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #757557
    Hi,

    you can fire the click function for the select all check box and do the operation, please verify bellow code snippet.

    // fire the check box checked change event
    $('#chkSelectAll').change(function () {

    // identify check box checked or not
    if ($('#chkSelectAll').attr('checked')) {

    // sets the checked property true for all based on class
    $('.chkSelect').each(function () {
    $(this).attr('checked', 'checked');
    });
    }
    else {
    // sets the checked property false for all based on class
    $('.chkSelect').each(function () {function () {
    $(this).removeAttr('checked');
    });
    }
    });

    Regards,
    SriSunny


  • Sign In to post your comments