在页面加载时将项目添加到ListBox并在单击按钮时将项目转移到另一个ListBox

JT4U

``此守则不起作用。请帮忙。'不确定在这里需要做什么。

Public Class WebForm2
    Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    ListBox1.Items.Add("test")
    ListBox1.Items.Add("test2")
End Sub

Protected Sub AddOneButton0_Click(sender As Object, e As EventArgs) Handles AddOneButton0.Click
    If (ListBox1.SelectedIndex = -1) Then
        MsgBox("please select an item")
    Else
        ListBox2.Items.Add(ListBox1.SelectedItem)
        ListBox1.Items.Remove(ListBox1.SelectedItem)
    End If
End Sub

末级

``添加HTML以帮助弄清楚我的代码是否做错了什么。

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="WebForm2.aspx.vb" Inherits="GBATExcel.WebForm2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <!DOCTYPE html>

<html>
<head>
    <title></title>
</head>
<body>
    <div style="height: 904px">

        <asp:ListBox ID="ListBox1" runat="server" style="position:absolute; top: 101px; left: 28px; height: 170px; width: 111px;"></asp:ListBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;

        <br />

        <asp:ListBox ID="ListBox2" runat="server" style="position:absolute; top: 103px; left: 223px; height: 167px; width: 131px;"></asp:ListBox>
        <asp:Button ID="RemoveAllButton" runat="server" Text="&lt;&lt;" style="position:absolute; top: 435px; left: 153px;"/>

        <asp:Button ID="AddOneButton2" runat="server" Text="&gt;" style="position:absolute; top: 308px; left: 157px;"/>

        <asp:Button ID="RemoveOneButton2" runat="server" Text="&lt;" style="position:absolute; top: 565px; left: 156px;"/>

        <asp:Button ID="AddAllButton" runat="server" Text="&gt;&gt;" style="position:absolute; top: 194px; left: 153px;"/>

        <asp:ListBox ID="ListBox3" runat="server" style="position:absolute; top: 302px; left: 29px; height: 177px; width: 106px;"></asp:ListBox>

        <asp:ListBox ID="ListBox4" runat="server" style="position:absolute; top: 520px; left: 223px; height: 170px; width: 129px;"></asp:ListBox>

        <asp:Button ID="AddOneButton0" runat="server" Text="&gt;" style="position:absolute; top: 110px; left: 157px;"/>

        <asp:Button ID="RemoveOneButton0" runat="server" Text="&lt;" style="position:absolute; top: 151px; left: 158px;"/>

        <asp:Button ID="RemoveAllButton0" runat="server" Text="&lt;&lt;" style="position:absolute; top: 233px; left: 154px;"/>

        <asp:ListBox ID="ListBox5" runat="server" style="position:absolute; top: 730px; left: 28px; height: 170px; width: 111px;"></asp:ListBox>

        <asp:ListBox ID="ListBox6" runat="server" style="position:absolute; top: 302px; left: 223px; height: 171px; width: 128px;"></asp:ListBox>

        <asp:Button ID="AddOneButton3" runat="server" Text="&gt;" style="position:absolute; top: 737px; left: 156px;"/>

        <asp:Button ID="RemoveOneButton3" runat="server" Text="&lt;" style="position:absolute; top: 350px; left: 157px;"/>

        <asp:Button ID="AddAllButton1" runat="server" Text="&gt;&gt;" style="position:absolute; top: 396px; left: 153px;"/>

        <asp:Button ID="RemoveAllButton1" runat="server" Text="&lt;&lt;" style="position:absolute; top: 648px; left: 152px;"/>

        <asp:ListBox ID="ListBox7" runat="server" style="position:absolute; top: 520px; left: 29px; height: 170px; width: 110px;"></asp:ListBox>

        <asp:ListBox ID="ListBox8" runat="server" style="position:absolute; top: 729px; left: 222px; height: 170px; width: 134px;"></asp:ListBox>

        <asp:Button ID="AddOneButton4" runat="server" Text="&gt;" style="position:absolute; top: 525px; left: 156px;"/>

        <asp:Button ID="RemoveOneButton4" runat="server" Text="&lt;" style="position:absolute; top: 776px; left: 156px;"/>

        <asp:Button ID="AddAllButton2" runat="server" Text="&gt;&gt;" style="position:absolute; top: 607px; left: 152px;"/>

        <asp:Button ID="AddAllButton0" runat="server" Text="&gt;&gt;" style="position:absolute; top: 819px; left: 152px;"/>

        <asp:Button ID="RemoveAllButton2" runat="server" Text="&lt;&lt;" style="position:absolute; top: 864px; left: 152px;"/>

    </div>
    </body>
    </html>
</asp:Content>

``基本上我对此有麻烦,需要一些帮助

康纳斯·范

您应该在Not IsPostBack条件中添加项目

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack Then
        ListBox1.Items.Add("test")
        ListBox1.Items.Add("test2")
    End If
End Sub

并将其从中删除,ListBox1然后再将其添加到ListBox2

Protected Sub AddOneButton0_Click(sender As Object, e As EventArgs) Handles AddOneButton0.Click
    If (ListBox1.SelectedIndex = -1) Then
        MsgBox("please select an item")
    Else
        Dim item As ListItem = ListBox1.SelectedItem
        ListBox1.Items.Remove(item)
        ListBox2.Items.SelectedIndex = -1
        ListBox2.Items.Add(item)
    End If
End Sub

注意:在将新项目插入ListBox2之前,必须重置所选项目

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

将项目添加到ListBox并将其绑定到另一个Listbox中的项目

来自分类Dev

将项目从一个listBox移到另一个listBox

来自分类Dev

如何将项目添加到选定的Listbox1项目中的另一个Listbox2项目中?

来自分类Dev

将项目转移到另一个帐户

来自分类Dev

将列表中的项目仅转移到另一个列表中

来自分类Dev

将项目转移到另一个帐户

来自分类Dev

JIRA:将项目转移到另一个 Atlassian 帐户

来自分类Dev

将项目从一个列表框转移到另一个

来自分类Dev

如何将一个静态列表的项目转移到另一个

来自分类Dev

遍历所有ListBox的选定项目,然后转移到一个ListBox

来自分类Dev

将已下载的源项目的引用添加到另一个项目时,得到“无法加载文件或程序集”

来自分类Dev

在pyiron中,如何将一些工作转移到另一个项目?

来自分类Dev

jQuery-在单击按钮时将表单上方的元素添加到另一个div

来自分类Dev

在Android Studio中从活动转移到另一个时加载

来自分类Dev

使用集合将列中的重复项转移到另一个页面

来自分类Dev

如何将http标头转移到另一个页面?

来自分类Dev

将控制权从一个按钮转移到另一个

来自分类Dev

如何将一个 DLL 编译按钮从一个 WPF 项目添加到另一个项目的事件处理程序?

来自分类Dev

从GridView将项目添加到ListBox

来自分类Dev

将项目从另一个活动添加到列表视图(仅添加一个项目)

来自分类Dev

在Google数据存储区中,如何将引用另一个实体的实体从一个项目转移到另一个项目?

来自分类Dev

将帖子从一个博客转移到另一个博客?

来自分类Dev

将一个JLabel的价值转移到另一个

来自分类Dev

将收集对象从一个jsp转移到另一个

来自分类Dev

将数据从一个$ state转移到另一个

来自分类Dev

将变量从一个功能转移到另一个功能

来自分类Dev

无法将一个标题下的值转移到另一个

来自分类Dev

Shopware 6.3-如何在将商店从一个域转移到另一个域时更改域名

来自分类Dev

单击按钮将组件添加到另一个组件

Related 相关文章

  1. 1

    将项目添加到ListBox并将其绑定到另一个Listbox中的项目

  2. 2

    将项目从一个listBox移到另一个listBox

  3. 3

    如何将项目添加到选定的Listbox1项目中的另一个Listbox2项目中?

  4. 4

    将项目转移到另一个帐户

  5. 5

    将列表中的项目仅转移到另一个列表中

  6. 6

    将项目转移到另一个帐户

  7. 7

    JIRA:将项目转移到另一个 Atlassian 帐户

  8. 8

    将项目从一个列表框转移到另一个

  9. 9

    如何将一个静态列表的项目转移到另一个

  10. 10

    遍历所有ListBox的选定项目,然后转移到一个ListBox

  11. 11

    将已下载的源项目的引用添加到另一个项目时,得到“无法加载文件或程序集”

  12. 12

    在pyiron中,如何将一些工作转移到另一个项目?

  13. 13

    jQuery-在单击按钮时将表单上方的元素添加到另一个div

  14. 14

    在Android Studio中从活动转移到另一个时加载

  15. 15

    使用集合将列中的重复项转移到另一个页面

  16. 16

    如何将http标头转移到另一个页面?

  17. 17

    将控制权从一个按钮转移到另一个

  18. 18

    如何将一个 DLL 编译按钮从一个 WPF 项目添加到另一个项目的事件处理程序?

  19. 19

    从GridView将项目添加到ListBox

  20. 20

    将项目从另一个活动添加到列表视图(仅添加一个项目)

  21. 21

    在Google数据存储区中,如何将引用另一个实体的实体从一个项目转移到另一个项目?

  22. 22

    将帖子从一个博客转移到另一个博客?

  23. 23

    将一个JLabel的价值转移到另一个

  24. 24

    将收集对象从一个jsp转移到另一个

  25. 25

    将数据从一个$ state转移到另一个

  26. 26

    将变量从一个功能转移到另一个功能

  27. 27

    无法将一个标题下的值转移到另一个

  28. 28

    Shopware 6.3-如何在将商店从一个域转移到另一个域时更改域名

  29. 29

    单击按钮将组件添加到另一个组件

热门标签

归档