locked
CheckBoxList Question (VB.NET) RRS feed

  • Question

  • Hi,

    I have a control on a webpage and in the markup I add a listitem and have used the index changed event

    Items are from 0 to 14 but items 1, 10 and 14 are ignored.

    I wish to check only one of the other boxes and when a new one is checked an existing one be unchecked.

    If I say:

    Protected Sub OnlyCheckOne (ByVal i As Integer)
    For intCheck = 0 To CheckBoxList1.Items.Count - 1
      If intCheck = 1 or intCheck = 10 or intCheck = 14 Then
        'Do Nothing
      Else
        CheckBoxList1.Items(intCheck).Selected = False
      End If
    Next
    CheckBoxList1.Items(i).Selected = True
    End Sub

    On running, I can check an item (example 12) then when I choose 13, 12 stays checked. However, not everytime but the majority if I have 13 checked then click on 12 the above sub works and the closer I get to index 0 it continues to be the same. How can I change the above to work perfectly each time?

    In the IndexChanged event, I have a select statement and are setting values depending on which of the checkboxes is selected. Also, I have a gender selector via 2 radio buttons and when male is selected all checkboxes except 1, 10 & 14 are disabled and re-enabled when the radio button is changed to female. So, I also need a way to find out which checkboxes are checked. It doesn't matter with indexes 1, 10 or 14 if the gender is male or female as box sexes are able to check 1 or more of them. Therefore, if I choose female, check one checkbox, change to male which disables them & still keeps that item checked, I wish for that checked value to be ignored if enabled = false.

    The enable/disable when gender changes works fine so it's checking only 1 of the 11 checkboxes and to get the values of the enabled checkboxes only.

    Any ideas?


    Homepage | YouTube Channel | Casual Kiss Dating Site

    Please mark 'as answer' if my solution helped you.

    • Moved by Carl Cai Thursday, July 24, 2014 1:29 AM (from vb) asp.net forum is more dedicated for these issues
    Wednesday, July 23, 2014 2:27 AM

Answers

  • If the question is ASP.Net related (which I believe due to the web page info) even though it's in VB.Net you should probably ask the question in one of the forums at ASP.Net as that's where questions about that kind of thing would probably receive the best answers from people experienced with web pages.

    La vida loca

    • Proposed as answer by Carl Cai Thursday, July 24, 2014 1:28 AM
    • Marked as answer by Just Karl Sunday, August 3, 2014 3:49 PM
    • Unmarked as answer by Crouchie1998 Monday, August 4, 2014 11:11 PM
    • Marked as answer by Just Karl Monday, September 22, 2014 9:11 PM
    Wednesday, July 23, 2014 2:42 AM

All replies

  • If the question is ASP.Net related (which I believe due to the web page info) even though it's in VB.Net you should probably ask the question in one of the forums at ASP.Net as that's where questions about that kind of thing would probably receive the best answers from people experienced with web pages.

    La vida loca

    • Proposed as answer by Carl Cai Thursday, July 24, 2014 1:28 AM
    • Marked as answer by Just Karl Sunday, August 3, 2014 3:49 PM
    • Unmarked as answer by Crouchie1998 Monday, August 4, 2014 11:11 PM
    • Marked as answer by Just Karl Monday, September 22, 2014 9:11 PM
    Wednesday, July 23, 2014 2:42 AM
  • ASP.NET website is a complete waste of time. All you get are people who paste links to resources that are absolutely no use whatsoever and not code. Example: I spend 14 hours on Google, cannot find the answer, post to ASP.NET asking for VB.NET and I will get a link to Javascript, F#, C++ which has absolutely no bearing on the question I asked because the replier has put 2 code words into Google and pasted in the first link avaialable. Then no-one bothers looking at the post because they see it's been answered then I spend days trying to research the answer myself. That happens 99.9% of the time on ASP.NET forums. Otherwise you have a moderator move the question from A VB forum there and you get links in any other language but the one you asked for

    I am a VS Ultimate with MSDN subscriber and are never going to waste my time in the ASP.NET forums again


    Homepage | YouTube Channel | Casual Kiss Dating Site

    Please mark 'as answer' if my solution helped you.

    Monday, August 4, 2014 11:11 PM
  • Is IndexChanged event being fired more times than expected?

    DIM Setting = False
    
    Protected Sub OnlyCheckOne (ByVal i As Integer)
    
    Setting = True
    For intCheck = 0 To CheckBoxList1.Items.Count - 1
      If intCheck = 1 or intCheck = 10 or intCheck = 14 Then
        'Do Nothing
      Else
        CheckBoxList1.Items(intCheck).Selected = False
      End If
    Next
    Setting = False
    
    ' IndexChanged event fired because of this statement? 
    
    CheckBoxList1.Items(i).Selected = True
    
    End Sub
    
    Protected Sub IndexChanged 
    IF Setting Then
    ELSE
       'Do Something proceed as normal
    END IF
    End Sub
    
    

    Monday, August 4, 2014 11:36 PM
  • All I see on forums.asp.net from any "Crouchie" are from Crouchie2004.

    I assume that's you.

    Anyhow, the first post that forums.asp.net seems to have from that nic is one complaining abuyt the time it takes to post and that people respond with less than helpful responses.

    As Mikesdotnetting says, Replies are not moderated. If you find that people offer you irrelevant links as possible solutions, use the Alert Moderators link to report them and we will remove replies if they are not relevant to the question.

    Suggesting to post ASP.Net questions on forums.asp.net IS the correct answer on these forums.

    We may disagree on the support one receives on forums.asp.net, but saying it's not the right place would be like going to a Cadillac forum and complaining about support you are receiving on a Corvette forum.

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C406F75746C6F6F6B2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

    Monday, September 22, 2014 9:16 PM