Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
XML
<pre lang="cs">function SelectAll(CheckBox) {
       var chkAc1 = document.getElementById(&#39;ctl00_MainContent_CheckBoxAccess&#39;).checked;
            if (document.getElementById(&#39;ctl00_MainContent_CheckBoxAccess&#39;).checked) {
           alert(&quot;chkd&quot;);
           var TargetBaseControl = document.getElementById(&#39;ctl00_MainContent_gvParentGrid_ctl02_gvChildGrid&#39;);
           var chkUIACCESS = document.getElementById(&#39;ctl00$MainContent$gvParentGrid$ctl02$gvChildGrid$ctl02$ui_access&#39;).value
       }
       else {            }
   }</pre>
  <asp:CheckBox ID="CheckBoxAccess" onclick="javascript:SelectAll(this);" runat="server" />
                           <Columns>
                                    <asp:BoundField DataField="UI_NAME" HeaderText="" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="20%" />
                                     <asp:TemplateField HeaderText="Access" HeaderStyle-HorizontalAlign="Left" >
                                        <ItemTemplate>
                                            <asp:CheckBox runat="server" ID="ui_access" />
                                        </ItemTemplate>
                                    </asp:TemplateField>


In my above code in script if CheckBoxAccess.checked = true then all chkbox(ui_access) should also get chkd in grid.
Posted
Updated 4-Aug-13 21:13pm
v7
Comments
Thanks7872 5-Aug-13 2:09am    
Repost. I have already pointed you out to some links where you can find even code for the same. Why dont you try something your self. Original post can be found at http://www.codeproject.com/Questions/631049/Global-checkboxes-for-grid-so-that-when-above-chkb
Member 9410081 5-Aug-13 2:41am    
i have chkd previous links u dent but couldn't get correct solution hence i have precise the code.
I have 7 columns of chkboxes each column has a top/global chkbox for selecting all below chkboxes. If u have any other solution let me know.
Thanks7872 5-Aug-13 2:46am    
There is no need for other solution. You have to modify your code. If you didnt get it,it doesnt mean to repost the question.
Member 9410081 5-Aug-13 2:54am    
the solutions u have sent are not simmilar to my post hence i have posted it.
My chkbox is outside the grid.
And the chkbox inside are handled by outside chkbox.

1 solution

Hi,

you can try something like below:

<script type="text/javascript">
// Select/Deselect checkboxes based on header checkbox
function SelectAll(headerchk) {

debugger
var gvcheck = document.getElementById('GridView1');
var i;
//Condition to check header checkbox selected or not if that is true checked all checkboxes
if (headerchk.checked) {

for (i = 1; i < gvcheck.rows.length; i++) {
var inputs = gvcheck.rows[i].getElementsByTagName('input');
inputs[0].checked = true;
}
}
//if condition fails uncheck all checkboxes in gridview
else {
for (i = 1; i < gvcheck.rows.length; i++) {
var inputs = gvcheck.rows[i].getElementsByTagName('input');
inputs[0].checked = false;
}
}
}

    </script>



XML
<asp:CheckBox ID="CheckBoxAccess" onclick="javascript:SelectAll(this);" runat="server" />
        <asp:GridView ID="GridView1" runat="server" AllowPaging="true" ForeColor="AliceBlue"
            BackColor="DodgerBlue" BorderColor="LightSkyBlue" HeaderStyle-BackColor="DarkBlue"
            AutoGenerateColumns="false">
            <Columns>

                <asp:TemplateField HeaderText="Access" HeaderStyle-HorizontalAlign="Left">
                    <ItemTemplate>
                        <asp:CheckBox runat="server" ID="ui_access" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>



it will solve your query.

Please mark if it help you.

Thanks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900