Setting the Selected Items on a Multi Select Listbox after Posback from Request

Joined
Jul 6, 2006
Messages
1
Reaction score
0
Hi there I have a bizarre problem. I have a Listbox which is multi select and submits to a database. This works fine. However once the form has submitted to the database it then postsback to the form and populates with the submitted values apart from this Listbox which only seems to get populated with the first selection made. So for instance if the user selects

19
20
22
24

the listbox will only show the 19 as being selected when actuall there were 3 other items selected.

Here is my page_load code

Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        decisionId = Utility.ParseInt(Request.QueryString("Id"), 0)
        Me.ConfigurePage()
        If Not IsPostBack Then

            ' NOT Postback
            Me.PopulateDropDowns()
            If Not decisionId = 0 Then
                Me.PopulateForm()
            Else
                Me.PopulalateNew()
            End If
            Me.ListJudgmentFiles()
        Else
            ' IS Postback
            Me.PopulateSubCategoryFromRequest(drpMainCategory, drpMainSubCategory)
        End If

    End Sub

and here is the procedure which gets called when there is a postback and populates the subcategory from the request.

Code:
Private Sub PopulateSubCategoryFromRequest(ByVal category As DropDownList, ByVal subcategory As ListBox)
        If Not category.SelectedItem.Value = -1 Then
            Utility.PopulateSubCategory(subcategory, category.SelectedItem.Value)

            Dim i As Integer
            Dim arySelectedSubcategoryItems() As String

            If Not Request(subcategory.ID.ToString).Equals(String.Empty) Then
                arySelectedSubcategoryItems = Request(subcategory.ID.ToString).ToString().Split(",")
                For Each i In arySelectedSubcategoryItems
                    For Each item As ListItem In subcategory.Items
                        If item.Value.Equals(i.ToString) Then
                            subcategory.Items.FindByValue(i).Selected = True
                        End If
                    Next
                Next
            End If
        End If
    End Sub


I cannot for the life of me work out why only one item is being selected. I have run the debugger and subcategory.Items.FindByValue(i).Selected = True seems to fire fine everytime it comes across a selected item, however once the form shows it loses the other values.

Please can anyone help?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top