Results 1 to 5 of 5

Thread: How to get which checkbox is checked? (In 150 checkbox)

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    15

    How to get which checkbox is checked? (In 150 checkbox)

    Is there a shorter way to get which checkbox checked in 150 checkbox other than;

    if checkbox1.checked = true then .....

    if checkbox2.checked = true then .....

    if checkbox150.checked = true then .....


    Thanks in advance.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    VB Code:
    1. Dim cb As CheckBox
    2. Dim c As Control
    3.  
    4.     For Each c In Controls
    5.         If TypeOf c Is CheckBox Then
    6.             cb = c
    7.             If cb.Checked Then
    8.                 Response.Write(cb.Name & " is checked")
    9.             End If
    10.         End If
    11.     Next

    Something like that.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    15
    Thank for reply. But I am very new to this.

    Do I have to import some namespace for that? Cause its gives me this compile error at this line

    Response.Write(cb.Name & " is checked")

    Error;
    Compiler Error Message: BC30456: 'Name' is not a member of 'System.Web.UI.WebControls.CheckBox'.

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    No, its just me confusing things. I was thinking of regular applications when I should have been thinking ASP. Try replacing Name with ID and it should work fine.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Posts
    15
    Worked. Thanks a lot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width