aspxgridview,checkbox and check all
-
hi, I am using an aspxgridview and two checkboxes(for header and dataitem).When I check header checkbox I want to check all checkbox.I am also using java script code.essentially, I can do this, but I must check header checkbox twice times.I didnt understand why it is happening.ı am writing this code checkbox_checked event and header checkbox's autopostpak is true. When I used normal gridview I didnt have any problem I could do this without problem.,
<script language="javascript" type="text/javascript">
function SelectAll(id) {var IsChecked = id.checked; var Chk = id; // Parent = document.getElementById('GrdPerliste'); Parent = document.getElementById('<% = GrdPerliste.ClientID%>'); var items = Parent.getElementsByTagName('input'); for (i = 0; i < items.length; i++) { var deneme = items\[i\].type; if (items\[i\].id != Chk && items\[i\].type == "checkbox") { if (items\[i\].checked != IsChecked) { items\[i\].click(); } } } } </script>
protected void Checksec_CheckedChanged2(object sender, EventArgs e) { CheckBox chk = (CheckBox)sender; GridViewHeaderTemplateContainer bulundugucontainer = (GridViewHeaderTemplateContainer)chk.NamingContainer; ((CheckBox)bulundugucontainer.FindControl("Checksec")).Attributes.Add("onclick", "javascript:SelectAll('" + ((CheckBox)bulundugucontainer.FindControl("Checksec")).ClientID + "')"); }
-
hi, I am using an aspxgridview and two checkboxes(for header and dataitem).When I check header checkbox I want to check all checkbox.I am also using java script code.essentially, I can do this, but I must check header checkbox twice times.I didnt understand why it is happening.ı am writing this code checkbox_checked event and header checkbox's autopostpak is true. When I used normal gridview I didnt have any problem I could do this without problem.,
<script language="javascript" type="text/javascript">
function SelectAll(id) {var IsChecked = id.checked; var Chk = id; // Parent = document.getElementById('GrdPerliste'); Parent = document.getElementById('<% = GrdPerliste.ClientID%>'); var items = Parent.getElementsByTagName('input'); for (i = 0; i < items.length; i++) { var deneme = items\[i\].type; if (items\[i\].id != Chk && items\[i\].type == "checkbox") { if (items\[i\].checked != IsChecked) { items\[i\].click(); } } } } </script>
protected void Checksec_CheckedChanged2(object sender, EventArgs e) { CheckBox chk = (CheckBox)sender; GridViewHeaderTemplateContainer bulundugucontainer = (GridViewHeaderTemplateContainer)chk.NamingContainer; ((CheckBox)bulundugucontainer.FindControl("Checksec")).Attributes.Add("onclick", "javascript:SelectAll('" + ((CheckBox)bulundugucontainer.FindControl("Checksec")).ClientID + "')"); }
try this javascript function
//cntrl- ID of the parent Check box
//grd - Cliend ID of the HTML Table or GridView in which all the check boxes
// are present
// indCat - 1 or 2 indicates call from parent or childfunction SelectAll(cntrl,grd,indCat)
{
var grdComp = document.getElementById(grd);if(indCat == '1') { for(i=1;i<=grdComp.getElementsByTagName('input').length-1;i++) { grdComp.getElementsByTagName('input')\[i\].checked = cntrl.checked; } } else if(indCat == '2') { var chkInd = true; for(i=1;i<=grdComp.getElementsByTagName('input').length-1;i++) { if(grdComp.getElementsByTagName('input')\[i\].checked == false) { chkInd = false; } } grdComp.getElementsByTagName('input')\[0\].checked = chkInd; }
}
hope this helps
with regards Karthik Harve
-
try this javascript function
//cntrl- ID of the parent Check box
//grd - Cliend ID of the HTML Table or GridView in which all the check boxes
// are present
// indCat - 1 or 2 indicates call from parent or childfunction SelectAll(cntrl,grd,indCat)
{
var grdComp = document.getElementById(grd);if(indCat == '1') { for(i=1;i<=grdComp.getElementsByTagName('input').length-1;i++) { grdComp.getElementsByTagName('input')\[i\].checked = cntrl.checked; } } else if(indCat == '2') { var chkInd = true; for(i=1;i<=grdComp.getElementsByTagName('input').length-1;i++) { if(grdComp.getElementsByTagName('input')\[i\].checked == false) { chkInd = false; } } grdComp.getElementsByTagName('input')\[0\].checked = chkInd; }
}
hope this helps
with regards Karthik Harve
thanks for your answer but my problem is that I have to check header checkbox twice.this works only when I check twice so when it works,header check seems not check