as the question says, I already can check the checkboxes in the gridview rows when the "Select All" CheckBox in the header is checked and uncheck the checkboxes in the gridview rows when the "Select All" CheckBox in the header is unchecked. And I want to do when not all of the checkboxes in the rows is checked, then the "Select All" CheckBox in the header is not checked, also vice versa (when all of the checkboxes in the rows is checked, then the "Select All" CheckBox in the header is checked).
How can I do that?
I already did like I want to achieve, but the checkbox in the header starts to affect (checked or unchecked) even I only check or uncheck a single checkbox in the rows, not all of them.
Here is the code that I am using:
protected void checkAll_CheckedChanged(object sender, EventArgs e)
{
CheckBox ChkBoxHeader = (CheckBox)GridView1.HeaderRow.FindControl("checkAll");
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox ChkBoxRows = (CheckBox)row.FindControl("chkbx_select");
if (ChkBoxHeader.Checked)
{
ChkBoxRows.Checked = true;
}
else
{
ChkBoxRows.Checked = false;
}
}
}
protected void chkbx_select_CheckedChanged(object sender, EventArgs e)
{
CheckBox chkbx_select = (CheckBox)sender;
CheckBox ChkBoxHeader = (CheckBox)GridView1.HeaderRow.FindControl("checkAll");
foreach (GridViewRow row in GridView1.Rows)
{
if (chkbx_select.Checked)
{
ChkBoxHeader.Checked = true;
}
else
{
ChkBoxHeader.Checked = false;
}
}
}
Your answer much appreciated.
Thank you.
Aucun commentaire:
Enregistrer un commentaire