【问题标题】:Mvc Contrib grid with checkbox带有复选框的 Mvc Contrib 网格
【发布时间】:2010-11-25 02:21:53
【问题描述】:

我正在寻找如何在标题上添加一个复选框的方法,该复选框支持选中或取消选中我的 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>  

【问题讨论】:

    标签: asp.net-mvc mvccontrib mvccontrib-grid


    【解决方案1】:
    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');
            }
        });
    });
    

    【讨论】:

      【解决方案2】:

      以下内容对我有用:

      column.For(x => Html.CheckBox('chkBox', x.Published)).Named('Published');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-17
        • 2011-01-26
        • 1970-01-01
        • 2011-05-14
        相关资源
        最近更新 更多