This is a migrated thread and some comments may be shown as answers.

Select all Checkboxes in Column - JavaScript

1 Answer 36 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rich
Top achievements
Rank 1
Rich asked on 19 Nov 2012, 02:10 PM
I have a page that had one column that I had to provide a "(Un)Check All" in the header.  I used this code to select or unselect them all and it works fine:

Here is the js code:
    function SelectAllCheckedChanged() {

        var grid = window['<%= rgManufacturerDisplay.ClientID %>'];

        var inputElements = grid.MasterTableView.Control.getElementsByTagName("INPUT");

        var headerChecked = window.event.srcElement.checked;

        var index;

 

        for (index = 0; index < inputElements.length; index++) {

            //NOTE: The GetElementsByTagName("INPUT") will return ALL input controls in the grid, so we have

            //to filter to the ones that we specfically care about.           

            if (inputElements[index].id.indexOf("chkDistributor") != -1) {

                //If the id of the control is "chkDistributor" then this is the checkbox in the Select column

                //for the grid row and we need to check/uncheck it (only if it's enabled).

                if (!inputElements[index].disabled) {

                    inputElements[index].checked = headerChecked;

                }

            }

        }

    }  


However now I have to add a second column, and need it to do the same thing...that is select or unselect all the rows in THAT column.

I've tried a couple of things, but not yet had much success.  The second column ID is chkContractor.

Anyone got any ideas of how I would do this with JavaScript?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Rich
Top achievements
Rank 1
answered on 19 Nov 2012, 10:03 PM
I figured out a way to do this that was very simple...I just created a function for each column and pointed the onclick to the correct funtion.  Wasn't as elegant, but works fine.
Tags
Grid
Asked by
Rich
Top achievements
Rank 1
Answers by
Rich
Top achievements
Rank 1
Share this question
or