WebHierarchicalDataGrid - get selected rows on Client

Alex Kartavov / Friday, October 29, 2010

In this small sample it is shown how to get selected rows in a WebHierarchicalDataGrid using recursion:

        <script type="text/javascript">

 

            function AddLine(gridView) {

 

                var events = document.getElementById("selection"); // gets reference to the DIV element

                var selectedRows = GetSelectedRows(gridView);

                for (var i = selectedRows.get_length() - 1; i >= 0; i--) {

                    if (gridView._level == 0)

                        events.innerHTML += selectedRows.getItem(i).get_cell(1).get_text() + "<br> "; // gets a refrence to the actor name cell

                    else

                        events.innerHTML += selectedRows.getItem(i).get_cell(2).get_text() + "<br> "; // gets a refrence to the title or song name cell

                }

 

            }

 

            function GetSelectedRows(gridView) {

                return gridView.get_behaviors().get_selection().get_selectedRows(); // gets the selected rows for the grid view

            }

 

            function GetChildGridView(gridView) {

                if (gridView._level == 0)

                    AddLine(gridView);

 

                var rows = gridView.get_rows(); // gets a reference to the container grid's rows

                for (var i = 0; i < rows.get_length(); i++) {

                    var childGridView = rows.get_row(i).get_rowIslands()[0]; // gets reference to the child grid view

                    if (childGridView) {

                        AddLine(childGridView); // adds a line with the current selected row to the DIV element

                        GetChildGridView(childGridView);

                    }

                }

            }

           

            function GetSelected() {

                var events = document.getElementById("selection");

                events.innerHTML = "";

                var grid = $find('<%= this.WebHierarchicalDataGrid1.ClientID %>');

                GetChildGridView(grid.get_gridView());

            }

        </script>

Enjoy!

ASP.NET team

ClientSideSelection.zip