Question

Je cherche la façon comment ajouter une case à cocher sur l'en-tête support cochée ou décochée toute ma colonne de case de mon girdview.

    <table class="grid">
    <th><input type="checkbox" name="chkall"/></th>
    <th>Name</th>
     <tr>
         <td>       
            <input type="checkbox" id="chkItem_1"/>
         </td>
         <td>
             Category 1
         </td> 
     </tr>
     <tr>
         <td>       
            <input type="checkbox" id="chkItem_2"/>
         </td>
          <td>
             Category 2
         </td>
     </tr>
</table>  
Était-ce utile?

La solution

column.For(x => Html.CheckBox("mycheckbox", new { @class = "foo" }))
    .DoNotEncode()
    .Header("<th><input type=\"checkbox\" id="chkHeader" /></th>");

Et vous pouvez ensuite utiliser jquery pour gérer l'événement de changement de la case en-tête et cocher / décocher toutes les autres:

$(function() {
    $('#chkHeader').change(function() {
        if ($(this).is(':checked')) {
            $('.foo').attr('checked', 'checked');
        } else {
            $('.foo').removeAttr('checked');
        }
    });
});

Autres conseils

Ce qui suit a travaillé pour moi:

column.For(x => Html.CheckBox('chkBox', x.Published)).Named('Published');
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top