0

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,

3
  • Got some example code to help? Commented 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.. Commented Jun 14, 2011 at 10:14
  • 1
    Get an idea from this thread stackoverflow.com/questions/1220715/… Commented Jun 14, 2011 at 10:15

1 Answer 1

0

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');
Sign up to request clarification or add additional context in comments.

2 Comments

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.
10x for your help, I had to change it a bit but it worked very good!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.