How do I use a checkbox to select rows in a repeat control?

We can use a checkbox in a view control to select documents for updating/deleting/etc but how do I create that same functionality in a repeat control?

I tried adding a checkbox bound to a session scope var, (onclick adds the docunid to the var), but I’m hung up on the update option. I can’t afford a full update every time the user checks a box - the repeat may have 100 rows in it. A partial update doesn’t seem to work for me either, because I don’t know how to set the value of the checkbox.

I found this lone article describing a method to do it, but I can’t get it to work. I’m using partial update on the checkbox control, and the value keeps resetting itself.

http://iqjam.net/iqjam/iqjam.nsf/questions/20100319_Checkbox_in_repeater_as_"Selec.htm

What’s the correct way to accomplish this?

Subject: SOLUTION: How to select rows in a repeat control.

I was unable to get the editable checkboxes working directly. The problems I had were how to bind them and also how to update (full/partial). So, after stumbling across this article by the great Declan Sciolla-Lynch:

I was able to adapt his approach and achieve my goal. To select a row, the user clicks a link in the repeat row (not the checkbox itself), which saves the docunid to a sessionscope var for processing (checkbox now shows as checked). My processing button runs on each docunid and then clears the sessionscope var.

Here’s what I did… I still have a checkbox in each row of my repeat control even though it isn’t clickable. It’s simply there to show which rows have been selected. It’s computed and visible but not editable. The data binding formula for my checkbox is the following:

var str = getComponent(“RowString”).getValue();

var rowarr = str.split(“~”);

var docunid = rowarr[15];

var sel=sessionScope.FlagDocs;

if (sel==null || sel==“”){

return("");

}

else {

var newval=@If(@Contains(sel, docunid), "Y","");

if (newval=="Y"){

	return("Y");

}

else {

	return("");

}

}

(how you get your docunid may vary)

This code will compute whether the checkbox should show as checked or not. If the docunid is in the sessionscope var, then it shows checked, otherwise not.

This is the code in my link, which either adds the docunid to the var or removes it. (set to partial update the repeat control id)

var str = getComponent(“RowString”).getValue();

var rowarr = str.split(“~”);

var docunid = rowarr[15];

var sel=sessionScope.FlagDocs;

if (sel==null){

var newval = docunid;

}

else {

var newval=@If(@Contains(sel, docunid),  @ReplaceSubstring(sel, docunid,""), sel+"~"+docunid);

}

sessionScope.FlagDocs = @Implode(@Trim(@Explode(newval,“~”)),“~”);

Pretty simple actually. Hope this helps someone else because I couldn’t find any other examples of how to do this.

Bob