Monday, March 1, 2010

Quick Tip: Checking all sub-items in a TreeView of checkboxes

For a project I'm working on, I had to have a tree view of checkboxes in order to facilitate filtering some search results. No big deal, that's what the ASP.Net TreeView control is for. However, I also needed a way to let selecting a checkbox at one node modify all of its children's checkboxes. And this is why I love JQuery:

$(".AdvancedFilter input:checkbox").click(function(){

$(this).closest("table").next("div").find("input:checkbox").attr("checked", $(this).attr("checked"));