Mvc Contrib grid with checkbox

后端 未结 2 1799
逝去的感伤
逝去的感伤 2021-01-16 07:39

I\'m looking for the way how to add a checkbox on the header that support checked or unchecked all my checkbox column of my girdview.

    
2条回答
  •  广开言路
    2021-01-16 08:39

    column.For(x => Html.CheckBox("mycheckbox", new { @class = "foo" }))
        .DoNotEncode()
        .Header("
");

And then you could use jquery to handle the change event of the header checkbox and check/uncheck all the others:

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

提交回复
热议问题