質問

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>  
役に立ちましたか?

解決

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

そして、jQueryを使用して、ヘッダーチェックボックスの変更イベントを処理し、他のすべてをチェック/チェックしてください。

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

他のヒント

以下は私のために働いています:

column.For(x => Html.CheckBox('chkBox', x.Published)).Named('Published');
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top