Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
285
Selecting check boxes in child rows when check box in parent rows is selected
posted

I need to check all the check boxes in one of the cell in the Child rows when a check box in the parent row is checked.  I need to get this done using javascript.  I am using WebhierarchicalDataGrid 9.2.

I am not familar with the Client methods.  I need methods to access WebhierarchicalDataGrid not the UltraWebGrid ( i guess the methods are different)

Thanks,

Hemant

 

  • 12679
    Suggested Answer
    posted

    Hello hemant_kg

     

    I’ve written this code a while ago. What the code do is when you check either uncheck a checkbox from parent Row,  the code check / uncheck all checkboxes in  its child rows.

     

    <script type="text/javascript">

     

            var whdg;

     

            function InitializHandler(sender, args) {

                whdg = sender;

            }

     

            var isChecked = false;

     

            // Loop through all child island's rows check either uncheck the checkbox according to parent row checkbox state.

            function ClickHandler(sender, args) {

     

               isChecked = args.get_item().get_row().get_cell(0).get_element().children[0].checked;

     

                var rowIndex  = args.get_item().get_row().get_index();

     

                var childGrids = whdg.get_rows().get_row(rowIndex).get_rowIslands();

     

                for (var j = 0; j < childGrids[0].get_rows().get_length(); j++) {

     

                    childGrids[0].get_rows()

                            .get_row(j).get_cell(0)

                            .get_element()

                            .children[0].checked = isChecked;

     

                }

            }

     

        </script>

        <form id="form1" runat="server">

        <div>

            <asp:ScriptManager ID="ScriptManager1" runat="server">

            </asp:ScriptManager>

            <ig:WebHierarchicalDataGrid ID="WebHierarchicalDataGrid1" runat="server" Height="350px"

                AutoGenerateBands="false" AutoGenerateColumns="false" DataMember="Parent" Width="832px"

                InitialDataBindDepth="1" InitialExpandDepth="1"

                DataKeyFields="id">

                <ClientEvents Initialize="InitializHandler"  Click="ClickHandler"/>

                <Columns>

                    <ig:TemplateDataField Key="CheckBox">

                     <ItemTemplate>

                        <asp:CheckBox ID="CheckBox2" runat="server" />

                     </ItemTemplate>

                    </ig:TemplateDataField>

                    <ig:BoundDataField Key="id">

                    </ig:BoundDataField>

                    <ig:BoundDataField Key="Data">

                    </ig:BoundDataField>

                </Columns>

                <Bands>

                    <ig:Band Key="ChildBand" DataMember="Child">

                        <Columns>

                            <ig:TemplateDataField Key="CheckBox">

                                <Header Text="CheckBox"/>

                                <ItemTemplate>

                                    <asp:CheckBox ID="CheckBox1" runat="server" />

                                </ItemTemplate>

                            </ig:TemplateDataField>

                            <ig:BoundDataField Key="id">

                            </ig:BoundDataField>

                            <ig:BoundDataField Key="Data">

                            </ig:BoundDataField>

                        </Columns>

                    </ig:Band>

                </Bands>

            </ig:WebHierarchicalDataGrid>

        </div>

        </form>

     

    Hope this helps