I have a datagirdview with a checkbox placed in header.How can i check or uncheck all checkboxes by clicking on checkbox that is in header.

i have found solution of my problem. . solution involve javascript so that page should not postback.

im posting it so that somebody else can benefit from it.

<script type="text/javascript">

    function SelectAll(id)
        var frm = document.forms[0];

        for (i=0;i<frm.elements.length;i++)
            if (frm.elements[i].type == "checkbox")
                frm.elements[i].checked = document.getElementById(id).checked;

In the code behind

Protected Sub grdDeletedADs_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdDeletedADs.RowDataBound
            If (e.Row.RowType = DataControlRowType.Header) Then
                DirectCast(e.Row.FindControl("chkAllRows"), CheckBox).Attributes.Add("onclick", "javascript:SelectAll('" & _
     DirectCast(e.Row.FindControl("chkAllRows"), CheckBox).ClientID & "')")

            End If
        Catch ex As Exception
        End Try
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.