Xavier
Xavier

Reputation: 1794

how to prevent disabled checkboxes of gridview from getting checked when select all checkbox is clicked?

I have used gridview in my aspx page.. In that i have a check box at each row including header..

By clicking the header checkbox it will check all the checkboxes including disabled checkboxes in gridview.. I need to avoid the disabled checkbox from getting checked

This is my gridview code:

<asp:GridView ID="CrowdRatingGrid" runat="server" AutoGenerateColumns="false" AllowPaging="true" PageSize="4" OnPageIndexChanging="CrowdRatingGrid_PageIndexChanging" ViewStateMode="Enabled">

<PagerSettings Mode="Numeric" PageButtonCount="4" />
<Columns>
<asp:TemplateField HeaderStyle-BackColor="#DBE2E2" HeaderStyle-Width="60px" HeaderStyle-HorizontalAlign="Center"
                HeaderStyle-Height="62px">
                <HeaderTemplate>
                    <asp:CheckBox ID="SelectAll" runat="server" onclick="SelectAll(this)" />

                </HeaderTemplate>
                <ItemTemplate>
                    <asp:CheckBox runat="server" ID="CheckRow" CssClass="SelectRow" />
                </ItemTemplate>
            </asp:TemplateField>
         </Columns>
        </asp:GridView>

This is my js code for selecting all checkbox:

function SelectAll(objRef) {

            var GridView = objRef.parentNode.parentNode.parentNode;
            var inputList = GridView.getElementsByTagName("input");
            for (var i = 0; i < inputList.length; i++) {
                var row = inputList[i].parentNode.parentNode;


                if (inputList[i].type == "checkbox" && objRef != inputList[i]) {
                    if (objRef.checked) {
                        inputList[i].checked = true;
                    }
                    else {
                        inputList[i].checked = false;
                    }
                }
            }
        }

Please help in achieving this? What change should i make in js to achieve my requirement?

Upvotes: 1

Views: 1577

Answers (1)

Adil
Adil

Reputation: 148120

Change condition to

 if (objRef.checked && !inputList[i].disabled) {
           inputList[i].checked = true;
 }
 else {
       inputList[i].checked = false;
 }

Upvotes: 3

Related Questions