Check all CheckBoxes in Telerik nested Grid in C#

 ̄綄美尐妖づ 提交于 2019-12-12 02:36:19

问题


Below is my code for nested grid of telerik:

  <telerik:RadGrid runat="server" ID="OrdersGrid" ShowFooter="True" AllowSorting="True"
                                    EnableLinqExpressions="false" GridLines="None"                OnInsertCommand="OrdersGrid_InsertCommand"
                                    OnItemCommand="OrdersGrid_ItemCommand" OnItemDataBound="OrdersGrid_ItemDataBound"
                                    Width="100%" HeaderStyle-CssClass="gridHeader" OnItemCreated="OrdersGrid_ItemCreated">
                                    <ClientSettings>
                                        <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                                    </ClientSettings>
                                    <MasterTableView ShowHeader="true" AutoGenerateColumns="False" PageSize="7" HierarchyLoadMode="Client"
                                        Font-Names="Verdana" Font-Size="12px" DataKeyNames="RIGHT_ID">
                                        <NestedViewTemplate>
                                            <telerik:RadGrid ID="brnchgrid" runat="server" OnItemDataBound="brnchgrid_ItemDataBound"
                                                CssClass="gridHeader" Width="100%">
                                                <MasterTableView DataSourceID="SqlDataSource1" AutoGenerateColumns="false" Font-Names="Verdana"
                                                    Font-Size="12px">
                                                    <Columns>
                                                        <telerik:GridBoundColumn HeaderText="Branch CODE" DataField="BRNCH_CODE" Visible="false">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridBoundColumn HeaderText="Branch name" DataField="BRNCH_NAME" UniqueName="BRNCH_NAME">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridTemplateColumn UniqueName="add" HeaderText="ADD" HeaderStyle-Width="50px">

                                                            <ItemTemplate>
                                                                <asp:CheckBox ID="chkadd" runat="server" />
                                                            </ItemTemplate>
                                                            <HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="50px" />
                                                            <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" Width="50px" />

                                                        </telerik:GridTemplateColumn>

I want to give an option to check all in the header in nested grid inside brnchgrid. The checkbox column is named add.


回答1:


In your markup set the header text to contain a checkbox which calls a function to check all the checkboxes onclick.

<telerik:GridTemplateColumn UniqueName="add" HeaderText="<input type='checkbox' id='checkAll' onclick='checkAll(this, gridToCheckAll);'>" HeaderStyle-Width="50px">

then in javascript

<script>
    var gridToCheckAll = '<%= brnchgrid.ClientID %>';

    function checkAll(sender, containerID) {
            var checked = sender.checked;
            var container = document.getElementById(containerID);
            var checkboxes = container.getElementsByTagName('input');
            for (var i = 0, l = checkboxes.length; i < l; i++) {
                if (checkboxes[i] != sender && !checkboxes[i].disabled)
                    checkboxes[i].checked = checked;
            }
        }
</script>


来源:https://stackoverflow.com/questions/12685944/check-all-checkboxes-in-telerik-nested-grid-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!