Quantcast
Channel: .NET Adventures - Client side
Viewing all articles
Browse latest Browse all 7

Check all CheckBoxes in GridView in client side

$
0
0

'Lists' controls as GridView, DataList or Repeater sometimes have a column with CheckBoxes. It is very usefull to let the user 'Select all' or 'Un Select all'. One way to do it is to loop on the control in the code behind and check/un check the CheckBoxes, or faster way is to do it on the client side, using the same idea of my preview  post:

//
//  Select or unSelect checkboxes in grid view
//
function CheckAllCheckBoxes(aspxCheckBoxID, checkVal)
{
    var reg = new RegExp( aspxCheckBoxID + "$" );
    var pageElements = document.getElementsByTagName("*");
    for(i = 0; i < pageElements.length; i++) {
        elm = pageElements[i];
        if (elm.type == 'checkbox')
        {
            if (reg.test(elm.name))
            {  
                elm.checked = checkVal
            }
        }
    }
 }

Where 'aspxCheckBoxID' is the CheckBox server side name, and 'checkVal is value if to check all or uncheck all. So simple.

Happy coding 


Viewing all articles
Browse latest Browse all 7