Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a gridiew control and in the header row i have set a checkbox control and autopostback event is true.and also other one checkbox control on the <itemtemplate>
i want once i check the header row so all checkboxes which is exist in the &lt;itemtemplate&gt; they should also be check in one click .
i am sending my codes please check and find the error when i am wrong

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<columns> <asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="cbdeleteheader" runat="server" AutoPostBack="True" OnCheckedChanged="cbdeleteheader_CheckedChanged" />
</HeaderTemplate>
<itemtemplate>
<asp:CheckBox ID="cbdelete" runat="server" AutoPostBack="True" />


<asp:TemplateField HeaderText="EmployeeID">
<itemtemplate>
<asp:Label ID="lblemployeeID" runat="server" Text='<%# Bind("ID") %>'>


<asp:BoundField DataField="salary" HeaderText="Salary" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="start_date" HeaderText="Start Date" />
<asp:BoundField DataField="City" HeaderText="City" />




protected void cbdeleteheader_CheckedChanged(object sender, EventArgs e)
{
C#
foreach (GridViewRow gridrows in GridView1.Rows)
{
    ((CheckBox)gridrows.FindControl(&quot;cbdelete&quot;)).Checked = ((CheckBox)sender).Checked;
}


}
if i check header row so cbdeleteheader check boxes do not get check . please check
Posted

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