I'm building a MultiSelect UserControl in vb.net i have the following problem to populate my multiselect i have created. Example code is below
Javascript of SumoSelect() is client side everything is working only thing i need is programmatically set selected values or not :)
https://hemantnegi.github.io/jquery.sumoselect/
Multiselect.ascx
Property SelectedValues() As String()
Get
Return selValues.Value.Split(",")
End Get
Set(value As String())
For i As Integer = 0 To value.Length - 1
If i = 0 Then
selValues.Value = value(i)
Else
selValues.Value += "," + value(i)
End If
Next
End Set
End Property
Sub New()
Items = New Dictionary(Of Object, Object)
End Sub
Public Items As Dictionary(Of Object, Object)
Private Function CreateItems() As String
Dim sb As New StringBuilder()
For Each item In Items
sb.AppendFormat("<option value=""{0}"">{0}</option>", item.Key, item.Value)
Next
Return sb.ToString()
End Function
'' selValues is a HiddenField clientside
Set SelectedValues:
MultiSelect1.SelectedValues() = New String() {"Banana Color", "Green Color", "Juice Color"}
Population:
For Each item In PjtColor.Fetch(Nothing, Nothing, Nothing, Nothing)
MultiSelect1.Items.Add(item.ColorName, item.ColorName)
Next
I need to compare SelectedValues(String Array) with Items(Dict)
to set sb.AppendFormat("<option value=""{0}"" selected=""selected"">{0}</option>", item.Key, item.Value)
to selected and when not matching to
sb.AppendFormat("<option value=""{0}"">{0}</option>", item.Key, item.Value)
Based on: http://hemantnegi.github.io/jquery.sumoselect/sumoselect_demo.html
I render it into a Literal which outputs the <options></option>
inside the <select></select>
Thanks in advance.
This is the question to my Answhere