Nested Gridviews header template checkbox issue

I have a nested gridview in which I am trying to get 'select all' functionality working. In the Header Template I want a checkbox that when checked will select all of the checkboxes in that grid.

Below is the code that I have in the aspx page. I added the radiobutton and the button as a test, both work as intended and select the child checkboxes by firing the systemSelectAll_CheckChanged() event in the code behind. The chkApproveAll checkbox does not fire this event at all. I can use a button or radiobutton if necessary, but a checkbox would give more consistent look to the page.

Any ideas as to why the checkbox does not fire the event while the radiobutton and button both do? The chkApprove checkbox in the ItemTemplate above it works fine as well.


<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
 <ItemTemplate>
    <asp:CheckBox ID="chkApprove" runat="server" OnCheckedChanged="systemApprove_CheckChanged" AutoPostBack="true" />
  </ItemTemplate>
  <HeaderTemplate>
  <asp:Label ID="lblApprove" Text="Approve&#10;All" runat="server" /><br /><br />  
 
<asp:RadioButton ID="rbApproveAll" runat="server" AutoPostBack="true" OnCheckedChanged="systemSelectAll_CheckChanged" />
           
<asp:CheckBox ID="chkApproveAll" runat="server" OnCheckChanged="systemSelectAll_CheckChanged" TextAlign="Left" AutoPostBack="true"/>

<asp:Button ID="btnApprove" runat="server" OnClick="systemSelectAll_CheckChanged" />
</HeaderTemplate>
</asp:TemplateField>
LVL 18
Jerry MillerAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Rajar AhmedConnect With a Mentor ConsultantCommented:
jmiller1979,
   Hi mate ,  this was a  nightmare for me ,  i tried yesterday till latenight but no result found and still i dint found it untill a hack thought arised .
 If you are desperate to get the solution you can however hack by using following code.
How it works :

1. Step1

Replace header checkbox markup to   <asp:CheckBox ID="chkApproveAll" runat="server"  onclick="hackthis();"    />
 

2. Step2

Create a invisible button with onclick action set to chkApproveAll_CheckedChanged  <asp:Button ID="Button1" runat="server" Text="Invisible button" OnClick="chkApproveAll_CheckedChanged" style="display:none;"/>

3. Step3

Add the script which will rise the invisible button click post back event .
 <script>
        function hackthis() {
               document.getElementById("<%=Button1.ClientId%>").click();
        }
    </script>
  <asp:Button ID="Button1" runat="server" Text="Invisible button" OnClick="chkApproveAll_CheckedChanged" style="display:none;"/>

<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
 <ItemTemplate>
    <asp:CheckBox ID="chkApprove" runat="server" OnCheckedChanged="systemApprove_CheckChanged" AutoPostBack="true" />
  </ItemTemplate>
  <HeaderTemplate>
  <asp:Label ID="lblApprove" Text="Approve&#10;All" runat="server" /><br /><br />   
 
<asp:RadioButton ID="rbApproveAll" runat="server" AutoPostBack="true" OnCheckedChanged="systemSelectAll_CheckChanged" />

<asp:CheckBox ID="chkApproveAll" runat="server"  onclick="hackthis();"    />

<asp:Button ID="btnApprove" runat="server" OnClick="systemSelectAll_CheckChanged" />
</HeaderTemplate>
</asp:TemplateField>

Open in new window


Hope this helps you
Meeran03
0
 
Jerry MillerAuthor Commented:
Thanks, I didn't think about using a hidden control.
0
All Courses

From novice to tech pro — start learning today.