vb.net: How to check or uncheck all chekboxes by clicking only one checkbox.

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2008
Posts: 43
Reputation: fawadkhalil is an unknown quantity at this point 
Solved Threads: 1
fawadkhalil fawadkhalil is offline Offline
Light Poster

vb.net: How to check or uncheck all chekboxes by clicking only one checkbox.

 
0
  #1
33 Days Ago
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 43
Reputation: fawadkhalil is an unknown quantity at this point 
Solved Threads: 1
fawadkhalil fawadkhalil is offline Offline
Light Poster
 
0
  #2
33 Days Ago
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.

  1. <script type="text/javascript">
  2.  
  3. function SelectAll(id)
  4. {
  5. var frm = document.forms[0];
  6.  
  7. for (i=0;i<frm.elements.length;i++)
  8. {
  9. if (frm.elements[i].type == "checkbox")
  10. {
  11. frm.elements[i].checked = document.getElementById(id).checked;
  12. }
  13. }
  14. }
  15. </script>

In the code behind

  1. Protected Sub grdDeletedADs_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdDeletedADs.RowDataBound
  2. Try
  3. If (e.Row.RowType = DataControlRowType.Header) Then
  4. DirectCast(e.Row.FindControl("chkAllRows"), CheckBox).Attributes.Add("onclick", "javascript:SelectAll('" & _
  5. DirectCast(e.Row.FindControl("chkAllRows"), CheckBox).ClientID & "')")
  6.  
  7. End If
  8. Catch ex As Exception
  9. lblerror.Text=ex.Message
  10. End Try
  11. End Sub
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC