I have nested repeaters and checkbox in each row(like a tree view or ctaegory and items view). each check/uncheck the category should check/uncheck the items. any suggestions? Thanks,
-
Got some example code to help?John– John2011-06-14 10:13:48 +00:00Commented Jun 14, 2011 at 10:13
-
I think it would be best done in JS - f.ex. jQuery. Then on each checkbox change - you could just do the same with it's children..ub1k– ub1k2011-06-14 10:14:56 +00:00Commented Jun 14, 2011 at 10:14
-
1Get an idea from this thread stackoverflow.com/questions/1220715/…Muhammad Akhtar– Muhammad Akhtar2011-06-14 10:15:04 +00:00Commented Jun 14, 2011 at 10:15
Add a comment
|
1 Answer
I had to do this before and I've done it with a simple JavaScript. Basically, when you bind you repeater, give the CategoryId to the checkbox's check event, e.g.
onchange="SelectCategory('<%# Eval("CategoryID") %>')"
have your child items wrapped around in a div with ID ending with CategoryId, e.g.
<div ID="divItems'<%# Eval("CategoryID") %>'">...</div>
this will allow you to find it in your SelectCategory(catId) function by doing
itemsDiv = document.GetElementById("divItems" + catId);
loop through its children and check your items:
var items = itemsDiv.getElementsByTagName('INPUT');
for (var i=0; i < items.length; i++) {
if (collection[i].type.toUpperCase() == 'CHECKBOX')
collection[i].checked = true; // or even "= CategoryCheckbox.checked"
}
even better with jQuery:
$('#divItems' + catId).find(':checkbox').attr('checked', 'checked');
2 Comments
Ruslan
It should work fine with asp:CheckBox controls (server-side ones). The only thing to note is that client-side IDs of those controls may be different from what you expect. Do a View Source to see what I mean.
DubiOO
10x for your help, I had to change it a bit but it worked very good!