Asp.net 如何将多个选定的listbox项获取到另一个listbox
在我的ASP.NET应用程序中,我有两个列表框,比如Listbox1和Listbox2。Listbox1具有一些listitems,并且处于多选模式。如果我按下传输按钮,Listbox1中的选定项目应移动到Listbox2。我尝试过单选动作,效果很好。 现在我需要选举的帮助 单选代码Asp.net 如何将多个选定的listbox项获取到另一个listbox,asp.net,vb.net,listbox,Asp.net,Vb.net,Listbox,在我的ASP.NET应用程序中,我有两个列表框,比如Listbox1和Listbox2。Listbox1具有一些listitems,并且处于多选模式。如果我按下传输按钮,Listbox1中的选定项目应移动到Listbox2。我尝试过单选动作,效果很好。 现在我需要选举的帮助 单选代码 strItemText = lstAvailableItems.SelectedItem.Text iItemCode = lstAvailableItems.SelectedValue
strItemText = lstAvailableItems.SelectedItem.Text
iItemCode = lstAvailableItems.SelectedValue
lstAvailableItems.Items.Remove(New ListItem(strItemText, iItemCode))
lstSelectedItems.Items.Add(New ListItem(strItemText, iItemCode))
列表框图像
如果我按下>按钮,单个选定项目将从可用项目列表框移动到选定项目列表框。如何对多个选择执行此操作?使用列表。迭代列表框中的所有项目,并将其添加到列表中
Dim lstRemoveItem As New List(Of ListItem)
For Each _item As ListItem In lstAvailableItems.Items
If _item.Selected Then
lstRemoveItem.Add(_item)
'here, method to add item to the first list.
End If
Next
For Each _item As ListItem In lstRemoveItem
lstSelectedItems.Items.Add(_item)
Next
不完全是您想要的,但您可以轻松配置变量。使用列表。迭代列表框中的所有项目,并将其添加到列表中
Dim lstRemoveItem As New List(Of ListItem)
For Each _item As ListItem In lstAvailableItems.Items
If _item.Selected Then
lstRemoveItem.Add(_item)
'here, method to add item to the first list.
End If
Next
For Each _item As ListItem In lstRemoveItem
lstSelectedItems.Items.Add(_item)
Next
不完全是您想要的,但您可以轻松配置变量。使用列表。迭代列表框中的所有项目,并将其添加到列表中
Dim lstRemoveItem As New List(Of ListItem)
For Each _item As ListItem In lstAvailableItems.Items
If _item.Selected Then
lstRemoveItem.Add(_item)
'here, method to add item to the first list.
End If
Next
For Each _item As ListItem In lstRemoveItem
lstSelectedItems.Items.Add(_item)
Next
不完全是您想要的,但您可以轻松配置变量。使用列表。迭代列表框中的所有项目,并将其添加到列表中
Dim lstRemoveItem As New List(Of ListItem)
For Each _item As ListItem In lstAvailableItems.Items
If _item.Selected Then
lstRemoveItem.Add(_item)
'here, method to add item to the first list.
End If
Next
For Each _item As ListItem In lstRemoveItem
lstSelectedItems.Items.Add(_item)
Next
不完全是您想要的,但是您可以轻松地配置变量。我的原创和@Arman的组合
Dim lstRemoveItem As New List(Of ListItem)
For Each li As ListItem In lstAvailableItems.Items
If li.Selected Then
lstRemoveItem.Add(New ListItem(li.Text, li.Value))
' can't remove from the collection while looping through it
End If
Next
For Each li As ListItem In lstRemoveItem
lstSelectedItems.Items.Add(li) ' add to "selected" items
lstAvailableItems.Items.Remove(li) ' remove from the original available items
Next
我的原版和@Arman的组合
Dim lstRemoveItem As New List(Of ListItem)
For Each li As ListItem In lstAvailableItems.Items
If li.Selected Then
lstRemoveItem.Add(New ListItem(li.Text, li.Value))
' can't remove from the collection while looping through it
End If
Next
For Each li As ListItem In lstRemoveItem
lstSelectedItems.Items.Add(li) ' add to "selected" items
lstAvailableItems.Items.Remove(li) ' remove from the original available items
Next
我的原版和@Arman的组合
Dim lstRemoveItem As New List(Of ListItem)
For Each li As ListItem In lstAvailableItems.Items
If li.Selected Then
lstRemoveItem.Add(New ListItem(li.Text, li.Value))
' can't remove from the collection while looping through it
End If
Next
For Each li As ListItem In lstRemoveItem
lstSelectedItems.Items.Add(li) ' add to "selected" items
lstAvailableItems.Items.Remove(li) ' remove from the original available items
Next
我的原版和@Arman的组合
Dim lstRemoveItem As New List(Of ListItem)
For Each li As ListItem In lstAvailableItems.Items
If li.Selected Then
lstRemoveItem.Add(New ListItem(li.Text, li.Value))
' can't remove from the collection while looping through it
End If
Next
For Each li As ListItem In lstRemoveItem
lstSelectedItems.Items.Add(li) ' add to "selected" items
lstAvailableItems.Items.Remove(li) ' remove from the original available items
Next
很好,谢谢。。在我的LSTAvableItems中,我有4000件物品。调试时,执行它以获取所选项目的时间太长。。还有其他简单的方法吗?@Manivel,getselecteddinces获取当前所选项目的索引值数组,但我不知道它有多快
Dim selectedValues()As Integer=lstAvailableItems.GetSelectedIndices()
对于这么多的项目,通常建议使用不同的用户界面元素(可能允许用户按部分项目(如AR12FC)进行搜索,然后从较短的列表中进行选择——但我不是UI专家)。工作正常,谢谢。。在我的LSTAvableItems中,我有4000件物品。调试时,执行它以获取所选项目的时间太长。。还有其他简单的方法吗?@Manivel,getselecteddinces获取当前所选项目的索引值数组,但我不知道它有多快Dim selectedValues()As Integer=lstAvailableItems.GetSelectedIndices()
对于这么多的项目,通常建议使用不同的用户界面元素(可能允许用户按部分项目(如AR12FC)进行搜索,然后从较短的列表中进行选择——但我不是UI专家)。工作正常,谢谢。。在我的LSTAvableItems中,我有4000件物品。调试时,执行它以获取所选项目的时间太长。。还有其他简单的方法吗?@Manivel,getselecteddinces获取当前所选项目的索引值数组,但我不知道它有多快Dim selectedValues()As Integer=lstAvailableItems.GetSelectedIndices()
对于这么多的项目,通常建议使用不同的用户界面元素(可能允许用户按部分项目(如AR12FC)进行搜索,然后从较短的列表中进行选择——但我不是UI专家)。工作正常,谢谢。。在我的LSTAvableItems中,我有4000件物品。调试时,执行它以获取所选项目的时间太长。。还有其他简单的方法吗?@Manivel,getselecteddinces获取当前所选项目的索引值数组,但我不知道它有多快Dim selectedValues()As Integer=lstAvailableItems.GetSelectedIndices()
对于这么多的项目,通常建议使用不同的用户界面元素(可能允许用户按部分项目(如AR12FC)搜索,然后从较短的列表中进行选择——但我不是UI专家)。