1

I'm working with Jquery datatables with asp.net repeaters and 90% of everything is working ok. Problem is that I've got a column of checkboxes and if I page through the datatable checking some boxes and then submit, I only get the last page of details, it forgets all other pages where checkboxes were checked.

This is covered more or less here:

http://www.datatables.net/forums/discussion/7700/repeater-checkbox-and-paging/p1

However, I've no idea how to get that data from an asp.net postback, anyone shed any light on how I'd be able to iterate through the repeater and get all checked boxes?

Thanks.

1
  • Anyone? I suppose I could use some sort of postback oncheckchanged solution but it's not ideal and could be messy. Anyone know of a better solution which would tie in nicely with .net's postback model? Commented Feb 6, 2012 at 10:08

2 Answers 2

1

I would add click handler on each check box that adds/remove id of the selected checkbox in some list (e.g. as a content of some hidden field as a comma separated list or something similar).

When you post form you can read this content from Request["hiddenFieldName"], split it by comma and save it.

Regarding the lost checkbox values on page change there is not direct solution. My choice would be to bind "page" event handler to datatable - something like this:

$('#example')
    .bind('page',   function () { populateCheckboxes(  ); })
    .dataTable();  

function populateCheckboxes will be called on each page change and here you can go through all checkboxes in the table and check whether their value is in the list in the hidden field.

Sorry but there is not easier solution for this, however this is not too complex script either.

Jovan

Sign up to request clarification or add additional context in comments.

Comments

0

Use the below approach in your code-behind. "rptrPayableItems" is the name of repeater.

foreach (RepeaterItem ri in rptrPayableItems.Items){                    
  CheckBox cbPaid = (CheckBox)ri.FindControl("chkbxPayItem");
  if (cbPaid.Checked){       
    //Do your operation here for checked checkbox.
  }
}

1 Comment

Unfortunately that doesn't work. With Datatables, if you've paged then when you iterate through the repeater in code behind it doesn't remember the items checked on the other pages.

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.