Thursday, October 28, 2010

select all checkbox in asp.net

 function SelectAll(id)
{
        var frm = document.forms[0];
        for (i=0;i
    {
            if (frm.elements[i].type == "checkbox")
        {
                frm.elements[i].checked = document.getElementById(id).checked;
                }
        }
 

Place this text in your source File :
{         
       
   //  HeaderTemplate in tag <>  //

 // asp:CheckBox ID="chkAll" runat="server"  in tag <>//

 //  HeaderTemplate in tag <>//

      


}   
In Code File
  protected void grdmember_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            //adding an attribute for onclick event on the check box in the header
            //and passing the ClientID of the Select All checkbox
            ((CheckBox)e.Row.FindControl("chkAll")).Attributes.Add("onclick", "javascript:SelectAll('" + ((CheckBox)e.Row.FindControl("chkAll")).ClientID + "')");
        }
    }

No comments:

Post a Comment