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

    Checkbox list selection

    hi all

    i am using chechbox and checkboxlist in my page.

    when user checks checkbox, all the items in the checkboxlist has to be selected and un checks, all the items in the checkboxlist has to be unselected.
    checkbox id is chkAll
    checkboxlist id is Cbx

    below is my code in js

    <script type="text/javascript">
    $(function () {
    $("[id*=chkAll]").bind("click", function () {
    if ($(this).is(":checked")) {
    $("[id*=Cbx] input").attr("checked", "checked");
    } else {
    $("[id*=Cbx] input").removeAttr("checked");
    $("[id*=Cbx] input").bind("click", function () {
    if ($("[id*=Cbx] input:checked").length == $("[id*=cblitems] input").length) {
    $("[id*=chkAll]").attr("checked", "checked");
    } else {

    above code is working fine for first time(checked and unchecked).
    But second time it is not working fine
    please correct my code.
  • #763964
    you removed the attribute. If the check box not checked.

    You can blank the checked attribute as follows

    if ($(this).is(":checked")) {
    $("[id*=Cbx] input").attr("checked", "checked");
    } else {
    $("[id*=Cbx] input").attr("checked", "");

    By Nathan
    Direction is important than speed

  • #763971

    When you use javascripts function in if there is postback then you need to re-register your script in server side. You can do that on page load using register.clientscriptblock() function.

    If you are unable to do something properly for the first time, call it Version 1.0!

    Thanks & Regards,

  • Sign In to post your comments