/ Published in: jQuery

This code can be used to create a MVC View User Control (.ascx) that will display a cascade or select all button with a clear button for checkboxes arranged in a hierarchy.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<%@ Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl" %> <% Dim Args() As String = ViewData("Args").ToString.Split(",") Dim SelectType As String = Args(0) Dim Label As String = Args(1) If SelectType = "Cascade" Then %> <input type="button" id="cascade" class="StandardButton" value="Cascade" /> <% Else%> <input type="button" id="selectall" class="StandardButton" value="Select All" /><br /> <% End If%> <input type="button" id="clear" class="StandardButton" value='<%= Label %>' /> <script type="text/javascript" language="javascript"> $(document).ready(function() { $('#selectall').click(function() { $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', true); }); $('#clear').click(function() { $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', false); }); $('#cascade').click(function() { $("div input[type='checkbox']").each(function() { if ($(this).attr('checked') == true) { $(this).siblings('div:eq(0)').find(':checkbox').attr('checked', true); } }); }); }); </script>
Comments
