dimanche 1 décembre 2019

how to get html chekbox at code behind with asp.net 4.0

here this is my html markup :

<asp:TemplateField>
                                <HeaderTemplate>
                                    <div class="form-check">
                                        <input type="checkbox" id="chkAll" runat="server" class="form-check-input checkAll" onclick="javascript:form1.submit();"  onserverchange="Server_Changed" />
                                        <label class="form-check-label">Roll No</label>
                                    </div>
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <div class="form-check">
                                        <input type="checkbox" id="chkSelect" runat="server" class="form-check-input" />
                                        <label class="form-check-label">
                                            <asp:LinkButton runat="server" CausesValidation="false" ID="lnkID" CommandName="detail"
                                                CommandArgument='<%#Bind("ID") %>' ToolTip="View Detail" 
                                                Text='<%# string.Concat("#",Eval("RollNo"))%>'
                                                Font-Underline="true">
                                            </asp:LinkButton>
                                        </label>
                                </ItemTemplate>
                            </asp:TemplateField>

and here is my code :

 protected void Server_Changed(object sender,EventArgs e)
    {
        CheckBox chkAll = sender as CheckBox;
        if (chkAll.Checked)
        {
            for (int i = 0; i <= egrd.Rows.Count - 1; i++)
            {
                GridViewRow row = egrd.Rows[i];
                CheckBox Ckbox = (CheckBox)row.FindControl("chkSelect");
                Ckbox.Checked = true;
            }
        }
        else
        {
            for (int i = 0; i <= egrd.Rows.Count - 1; i++)
            {
                GridViewRow row = egrd.Rows[i];
                CheckBox Ckbox = (CheckBox)row.FindControl("chkSelect");
                Ckbox.Checked = false;
            }
        }
    }

here i achieve get all checkbox selected from html checkbox checked changed event..

how i done this task ...please guys help me...




Aucun commentaire:

Enregistrer un commentaire