0

下面是我的 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>

我想提供一个选项来检查brnchgrid内嵌套网格的标题中的所有内容。复选框列名为add

4

1 回答 1

0

在您的标记中,将标题文本设置为包含一个checkbox调用函数来检查所有复选框的函数onclick

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

然后在 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>
于 2012-10-17T19:08:16.640 回答