0
0
WPF: I need to check all the checkboxes when I click select all check box in the header of the datagrid in WPF.
0
<script type="text/javascript"> // Let's use a lowercase function name to keep with JavaScript conventions function selectAll(invoker) {
// Since ASP.NET checkboxes are really HTML input elements
// let's get all the inputs var inputElements = document.getElementsByTagName('input');
for (var i = 0 ; i < inputElements.length ; i++)
{ var myElement = inputElements[i]; // Filter through the input types looking for checkboxes if (myElement.type === "checkbox") { // Use the invoker (our calling element) as the reference // for our checkbox status
myElement.checked = invoker.checked;
}
}
}
</script> <!-- assuming that SqlDataSource1 is the datasource for my GridView -->
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"> <Columns> <asp:TemplateField> <AlternatingItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" /> </AlternatingItemTemplate> <ItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" /> </ItemTemplate> <HeaderTemplate> <asp:CheckBox ID="cbSelectAll" runat="server" Text="Select All" OnClick="selectAll(this)" /> </HeaderTemplate> <HeaderStyle HorizontalAlign="Left" /> <ItemStyle HorizontalAlign="Left" /> </asp:TemplateField> </Columns></asp:GridView>
