I have a grid that has grouping i.e the grid shows products of group. So, the structure has Group and its childs. Same way I will have some other groups and their childs which I am binding like below.I want to check and uncheck the entire sublist on the click of parent.
CSHTML
@{
if (Model.List.Count() > 0)
{
<table>
<tr>
<input type="checkbox" class="cls@(obj.GroupId)" name="@obj.GroupId" onclick="checkUncheckAll(this.class)" />
<td>Name</td>
</tr>
@foreach (var obj in Model.subList)
{
<tr>
<td>
<input type="checkbox" class="cls@(obj.GroupId)" name="@obj.GroupId" /></td>
</td>
<td>
@obj.Name
</td>
</tr>
</table>
}
}
<input type="button" value="Save" onclick="PickAllCheckedRows();" />
I have been trying to do this like below but no success. Also I want to pick all the checked group and its subitems on click of save button. Any help would be really appreciated.
<script type="text/javascript">
function checkUncheckAll(sender) {
alert(sender);
var chkElements = document.getElementsByClassName('chkItems');
for (var i = 0; i < chkElements.length; i++) {
chkElements[i].checked = sender.checked;
}
}
function PickAllCheckedRows() {
}
</script>