问题
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