0

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.

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by fawadkhalil
0

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
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.