Monday, April 18, 2005

Maintaining Checkbox state in Datagrid with paging

We can achieve it with JavaScript, and hidden variable.

Whenever on click of the checkbox, we call a javascript function passing ‘this’ as parameter, so that we know which checkbox we are checking. Anyway, for each checkbox, we must be having a unique PK or some value.

The logic is like this,

If checkbox is checked, then append it to hidden variable with CSV (comma separated values), else if u uncheck it, split it and loop thru the remaining values and append the remaining checked values with CSV to hidden variable. The hidden field as below,

[input type="hidden" id="hdnField" name=" hdnField” value="[%=Request.Form("hdnField")%]"]

Note: (Replace "[]" with "<>")

The script can be downloaded from: Script.txt

Hope this works…..Happy programming

This page is powered by Blogger. Isn't yours?