Javascript 建筑多选用户控件的问题
我正在vb.net中构建一个多选用户控件 我有以下问题来填充我创建的multiselect。 下面是示例代码 SumoSelect()的Javascript是客户端,一切正常,我唯一需要的是通过编程设置所选值或不设置:) Multiselect.ascxJavascript 建筑多选用户控件的问题,javascript,jquery,asp.net,linq,sumoselect.js,Javascript,Jquery,Asp.net,Linq,Sumoselect.js,我正在vb.net中构建一个多选用户控件 我有以下问题来填充我创建的multiselect。 下面是示例代码 SumoSelect()的Javascript是客户端,一切正常,我唯一需要的是通过编程设置所选值或不设置:) Multiselect.ascx Property SelectedValues() As String() Get Return selValues.Value.Split(",") End Get Set(
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
人口:
MultiSelect1.SelectedValues() = New String() {"Banana Color", "Green Color", "Juice Color"}
我需要将SelectedValues(字符串数组)与Items(Dict)进行比较
将sb.AppendFormat(“{0}”、item.Key、item.Value)
设置为选中,并且在与不匹配时设置为
sb.AppendFormat("<option value=""{0}"">{0}</option>", item.Key, item.Value)
sb.AppendFormat(“{0}”,item.Key,item.Value)
基于:
我将其渲染为一个文本,该文本在
中输出
提前谢谢。这是我想问的问题
For i As Integer = 0 To SelectedValues.Count - 1
SelectedItems.Add(SelectedValues(i), SelectedValues(i))
Next
For Each item In Items
If SelectedItems.ContainsKey(item.Key) Then
sb.AppendFormat("<option value=""{0}"" selected=""selected"">{0}</option>", item.Key, item.Value)
Else
sb.AppendFormat("<option value=""{0}"">{0}</option>", item.Key, item.Value)
End If
Next
对于i As Integer=0到SelectedValues。计数-1
添加(SelectedValues(i),SelectedValues(i))
下一个
对于项目中的每个项目
如果选择editems.ContainsKey(item.Key),则
sb.AppendFormat(“{0}”,item.Key,item.Value)
其他的
sb.AppendFormat(“{0}”,item.Key,item.Value)
如果结束
下一个
你说基于GitHub项目,但你没有在任何地方初始化SumoSelect()
。客户端的人没有发布这篇文章:)一切正常,但现在我想要列表中的选中选项,我需要将填充的Dict项与SelectedValues字符串数组进行比较
For i As Integer = 0 To SelectedValues.Count - 1
SelectedItems.Add(SelectedValues(i), SelectedValues(i))
Next
For Each item In Items
If SelectedItems.ContainsKey(item.Key) Then
sb.AppendFormat("<option value=""{0}"" selected=""selected"">{0}</option>", item.Key, item.Value)
Else
sb.AppendFormat("<option value=""{0}"">{0}</option>", item.Key, item.Value)
End If
Next