List box help

DowntownIT used Ask the Experts™
I have an accordion where I am creating each pane dynamically through code. I am then dynamically creating and adding a list box and list items to each of the panes. What I can’t figure out, is how to capture the selected value and text of any given list box. I also need to be able that if the user selects a item from the list box in any of the panes that all other selected list box items of the other panes are cleared.

Thanks for the help!
Public Sub BuildAccordion()

        Dim dt As DataTable = ListData1.DefaultView.ToTable("MyPanes", True, New [String]() {"Screen_no", "Screen_desc"})

        For Each row As DataRow In dt.Rows

            Dim myStrExpr As String
            myStrExpr = "screen_no = " & row("Screen_no").ToString
            Dim lbScreen As New ListBox

            For Each row1 As DataRow In ListData1.Select(myStrExpr)
                lbScreen.Items.Add(New ListItem(row1("Floor/Location/Position").ToString, "Seat_no"))

            CreateAccPane(row("Screen_desc").ToString, row("Screen_desc").ToString, lbScreen)
    End Sub

    Public Sub CreateAccPane(ByVal PaneID As String, ByVal PaneHeader As String, ByVal PaneContent As ListBox)
        Dim panel1 As AccordionPane = New AccordionPane
        panel1.ID = PaneID
        panel1.HeaderContainer.Controls.Add(New LiteralControl(PaneHeader))



    End Sub

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Dynamic controls are a complicated matter.
This article on might provide you with some insight -

I would try to avoid using dynamic controls if I were you. They can quickly turn into a headache.


I understand where you are coming from and perfer not to do it. As the page stands now, I am using only one list box but it contains a couple hundred items. I figured that I could break that list box into a few list boxes by a common grouping of the items. The problem is that the common grouping changes so in one run, I could have 4 groups and in the next I could have 5 groups. Open to suggestions for another path.

Hmm.. I'm not sure if this will work, but what if you add a DropDownList just above your ListBox, and use it to filter the items in the ListBox? The DropDownList would have your common groups listed, and when you select one, the ListBox only shows items from that group?

A little more info on the type of information you have in your ListBox and what its supposed to be used for, might help.


Didn't think of that, that will be the route I will go.

Thanks for the suggestion!

You're welcome :) Glad I could help!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial