944,156 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 1500
  • ASP.NET RSS
Nov 2nd, 2009
0

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

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
fawadkhalil is offline Offline
88 posts
since Dec 2008
Nov 2nd, 2009
0
Re: vb.net: How to check or uncheck all chekboxes by clicking only one checkbox.
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.

ASP.NET Syntax (Toggle Plain Text)
  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

ASP.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
fawadkhalil is offline Offline
88 posts
since Dec 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: urgent: Passing ArrayList in session..
Next Thread in ASP.NET Forum Timeline: session varible from 1 page to another





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC