Robert Robert - 1 year ago 393
jQuery Question

Get multiple selected values of Jquery's Select2 from code behind using

I'm combining Select2 with code behind to get the values. And now I want to get all the selected values using code behind too. But I can't get it to work. Here is my HTML code

<div class="form-group">
<select class="form-control select2" id="ddLokasi" multiple="true"
runat="server" data-placeholder="Pilih Lokasi" style="width:100%;">

As you can see, I manage to get the Select2 working on my web.
Here's the screenshot :
(sorry I can't embbed the image)

Now I want to get all the values that I already selected into an array. How to do this in code behind using VB ?


Answer Source

Do something like this in your code-behind:

  For i As Integer = 0 To ddLokasi.Items.Count
            If (ddLokasi.Items(i).Selected)
                //Get values
            End If


Dim listOfValues AS List(Of String) = new List(Of String)
        For Each item As ListItem In ddLokasi.Items
            If item.Selected Then
            End If
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download