[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 81
  • Last Modified:

ASP.net VB.net Get the Index of an Item checked in a dynamically added CheckBoxList

Hi
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
0
Murray Brown
Asked:
Murray Brown
  • 5
  • 4
1 Solution
 
AndyAinscowFreelance programmer / ConsultantCommented:
Is it a multi select check listbox ?  (They don't use the SelectedIndex - that is just for single selection)
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi. That doesn't work. It is a CheckBoxList not a ListBox
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
AndyAinscowFreelance programmer / ConsultantCommented:
Answer the question please. Is it a multi select check listbox ?
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
It is a CheckBoxList as I just said. This is automatically multi select
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
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.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
ps.  re your attention request:
Hi

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

Thanks


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?
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
I asked for the request to be ignored. I probably just interpreted your question differently to the way it was meant
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks for the help
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now