Select all rows from one checkbox in a GridView

Page Markup

<asp:GridView runat="server" ID="grdAbsentApprovals" ShowHeader="true" ShowHeaderWhenEmpty ="true"  Width="100%"
                            CssClass="mGrid" AutoGenerateColumns="False">
                               <AlternatingRowStyle BackColor="#EEEEEE" />
                <Columns>
                    <asp:TemplateField>
                    <HeaderTemplate>
                    <input type="checkbox" id ="chkSelectAll" onclick="SelectAllCheckboxes(this)"></checkbox>
                    </HeaderTemplate>
                        <ItemTemplate>
                            <asp:CheckBox runat="server" ID="chkItem" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="DOC_NO" HeaderText="DOC NO" SortExpression="DOC_NO" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" />
                   
                    <asp:BoundField DataField="NAME" HeaderText="NAME" SortExpression="NAME" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" />
                     <asp:BoundField DataField="NOOFDAYS" HeaderText="DAYS" SortExpression="NOOFDAYS" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" />
                    <asp:BoundField DataField="DESCRIPTION" HeaderText="DESCRIPTION" SortExpression="DESCRIPTION"  HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left"/>
                </Columns>
                <EmptyDataTemplate>
                No Data Found.
                </EmptyDataTemplate>
            </asp:GridView>

JavaScript

 

  function SelectAllCheckboxes(chk) {
                    $('#<%=grdAbsentApprovals.ClientID%>').find("input:checkbox").each(function () {
                        if (this != chk) { this.checked = chk.checked; }
                    });
                }

Musthaan

Advertisements

One thought on “Select all rows from one checkbox in a GridView

  1. I will immediately grab your rss feed as I can not find your email subscription link or enewsletter service. Do you’ve any? Please let me know in order that I could subscribe. Thanks. kdadgbfgbdce

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s