简体   繁体   English

将ListItems从一个ListBox复制到另一个

[英]Copy ListItems from one ListBox to another

I am implenting some functionality on asp.net page such that: There are to listboxes side by side, left one is prepopulated and right one is empty. 我在asp.net页面上强加了某些功能,例如:并排显示列表框,左一个预填充,右一个为空。 Besides left listbox there is add button and besides right there is remove button. 除了左侧列表框之外,还有添加按钮,而右侧则有删除按钮。 I have written javascript code such that on Add button click the selected listItems from left listbox are moved to right listbox and vice-versa. 我已经编写了JavaScript代码,以便在“添加”按钮上单击从左侧列表框中选择的listItem,将其移到右侧列表框中,反之亦然。

It is as follows: 如下:

在此处输入图片说明

When I submit the form, in code-behind I am not able to retrive the newly moved values from right ListBox (I know its not posssible in this way). 当我提交表单时,在代码背后,我无法从正确的ListBox检索新移动的值(我知道这种方式是不可能的)。 How can I access the changes made with the javascript changes to the listboxes in the codebehind . 如何访问对JavaScript代码背后的列表框所做的更改

Any help appreciated. 任何帮助表示赞赏。

I think while you are loading the page contents inside Page_Load(),make sure that you are loading after checking whether is a post back request or not.Load the events if it is not a postback request. 我认为在加载Page_Load()中的页面内容时,请确保在检查是否为回发请求之后进行加载。如果不是回发请求,则加载事件。

ie :- 即:-

    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
       {

        //load the contents of the page/listbox here.

       }

}
<form id="form1" runat="server">
    <div>
        <select id="greet" name="greet" multiple="multiple">
            <option>Mr</option>
            <option>Mrs</option>
            <option>Miss</option>
            <option>Dr</option>
        </select>
        <asp:Button Text="Submit" runat="server" ID="btnSubmit" 
                            OnClick="btnSubmit_Click" />
    </div>
</form>


 protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string greets = Request["greet"];

    }

I was able to view the selected items in the list 我能够查看列表中的选定项目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM