I m using gridview and there is a checkbox(with name Select all) in header to select all checkboxes in item template. when i click on this check box it select all the checkboxes in item template and display the delete button and on removing check it hide the delete button. Now, what i want is, when i click the select all checkbox and then if i remove all checkboxes from the item templates one by one the select all checkbox check to be removed and delete button go hide. if i select one or more checkbox from item template the delete button become visible, and if i deselect any checkbox the delete button should be visible until and unless all checkboxes are not cleared.
i try this code but not work properly. can anybody help me please?
this code is on Select All check boxes.
protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
Button btnDel = (Button)ViewsStudGV.FooterRow.FindControl("btnDel");
CheckBox allchk = (CheckBox)ViewsStudGV.HeaderRow.FindControl("chkSelectAll");
CheckBox chk;
foreach (GridViewRow rowItem in ViewsStudGV.Rows)
{
chk = (CheckBox)(rowItem.Cells[0].FindControl("chkSelect"));
chk.Checked = ((CheckBox)sender).Checked;
if (chk.Checked == true)
{
btnDel.Visible = true;
allchk.Text = "Select None";
}
else
{
btnDel.Visible = false;
allchk.Text = "Select All";
}
}
}
and this code is on item template checkbox
protected void chkSelect_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)ViewsStudGV.FindControl("chkSelect");
Button btnDel = (Button)ViewsStudGV.FooterRow.FindControl("btnDel");
CheckBox allchk = (CheckBox)ViewsStudGV.HeaderRow.FindControl("chkSelectAll");
CheckBox c = (CheckBox)sender as CheckBox;
if (c.Checked == true && allchk.Checked==true)
{
btnDel.Visible = true;
}
else if(c.Checked == false && allchk.Checked==true)
{
btnDel.Visible = false;
}
else if (c.Checked == true && allchk.Checked == false)
{
btnDel.Visible = true;
}
else if (c.Checked == false && allchk.Checked == false)
{
btnDel.Visible = false;
}
}