Solved Get the Index of an Item checked in a dynamically added CheckBoxList

Posted on 2016-10-21
Last Modified: 2016-10-21
I am trying to get the Index of an Item checked in a dynamically added CheckBoxList. I use the following code and
myCheckBoxListName  and myNewValue work just fine but oIndex returns -1 every time

  Private Sub HandleCheckBoxListOnSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

            Dim myCheckBoxListName As String
            Dim myNewValue As String
            Dim oIndex As Integer

            myNewValue = DirectCast(sender, CheckBoxList).SelectedValue
            oIndex = DirectCast(sender, CheckBoxList).SelectedIndex
            myCheckBoxListName = DirectCast(sender, CheckBoxList).ID
End Sub
Question by:murbro
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
LVL 44

Expert Comment

ID: 41853363
Is it a multi select check listbox ?  (They don't use the SelectedIndex - that is just for single selection)
LVL 44

Expert Comment

ID: 41853368

Author Comment

ID: 41853649
Hi. That doesn't work. It is a CheckBoxList not a ListBox
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 44

Expert Comment

ID: 41853660
Answer the question please. Is it a multi select check listbox ?

Author Comment

ID: 41853686
It is a CheckBoxList as I just said. This is automatically multi select
LVL 44

Accepted Solution

AndyAinscow earned 500 total points
ID: 41853697
OK, that is why your SelectedIndex fails.

You will have to loop through the items and check each individually if it is selected to build up your collection of indexs.
LVL 44

Expert Comment

ID: 41853703
ps.  re your attention request:

The tone of the person answering the question is not that polite. I think another expert should help or the question be deleted.


What is impolite for asking you to answer a question you know the answer to, everyone else doesn't know the answer to and is critical to be able to explain why your code doesn't work?

Author Comment

ID: 41853710
I asked for the request to be ignored. I probably just interpreted your question differently to the way it was meant

Author Closing Comment

ID: 41853713
Thanks for the help

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Change to file doesn't show up 16 74 Markup for Sub Menu 2 39
Get sourcecode path 14 46
Validation for a field in 3 10
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question