1. For inner check boxes, you need to identify the ID (or primary key) for the record (row) on check of that check-box and then you can store this ID in a hidden control (in comma separated format). You can do this using JQuery, I'm posting code for adding the ID value, hope you can write logic for ID removal (on uncheck of checkbox):
var ctrlValue = $("#hdn").val();
ctrlValue = ctrlValue +
$(ctrl).parents('tr').children().filter(function(index) {
return index == 1;
}).html() + ",";
$("#hdn").val(ctrlValue);
2. For outer checkbox you need to indentify all the checkboxes inside the listview and set them as checked. After that you can update the hidden control to store the IDs. I'll post code for this.
Please note that I've assumed that the checkbox is first control in each row.