Hi
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.

hey
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;
            }
        }
    }
</script>

In the code behind

Protected Sub grdDeletedADs_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdDeletedADs.RowDataBound
        Try
            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
            lblerror.Text=ex.Message
        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 meeting, networking, learning, and sharing knowledge.