nvt*_*ang 1 asp.net-mvc mvccontrib mvccontrib-grid
我正在寻找如何在标题上添加一个复选框的方式,该标题支持选中或取消选中我的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>
Run Code Online (Sandbox Code Playgroud)
column.For(x => Html.CheckBox("mycheckbox", new { @class = "foo" }))
.DoNotEncode()
.Header("<th><input type=\"checkbox\" id="chkHeader" /></th>");
Run Code Online (Sandbox Code Playgroud)
然后你可以使用jquery来处理标题复选框的更改事件并检查/取消选中所有其他事件:
$(function() {
$('#chkHeader').change(function() {
if ($(this).is(':checked')) {
$('.foo').attr('checked', 'checked');
} else {
$('.foo').removeAttr('checked');
}
});
});
Run Code Online (Sandbox Code Playgroud)
小智 5
以下对我有用:
column.For(x => Html.CheckBox('chkBox', x.Published)).Named('Published');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4628 次 |
| 最近记录: |