从列表框中删除项目

从列表框中删除项目

本文介绍了从列表框中删除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,
我正在使用java-script将项目添加到列表框;
现在,在Button单击服务器端事件时,当我尝试删除选定的项目时,我得到的项目计数为0;

我只想从服务器端单击事件中删除项目.

这是我对文本框的Keyup事件的了解.

Hi Friends,
I am adding items to List-box using java-script;
Now , on Button click server side event, when I try to remove selected items, I get item count 0;

I want to remove items from server side click event only.

This is what I have on Keyup event of text box.

<asp:TextBox ID="txtPONo" runat="server"  onKeyUp="inputKeyUp(event)"></asp:TextBox>
<asp:Button ID="btnAddToList" runat="server" OnClick="btnRemoveFromList_Click" Text="Remove PO" />

<script type="text/javascript">
    function inputKeyUp(e) {
        e.which = e.which || e.keyCode;
        if (e.which == 13) {
            var varFromBox = document.all(''lstPONo'');
            var ListBox = document.getElementById(''ctl00_MainContentPlaceHolder_lstPONo'');
            var TextBox = document.getElementById(''ctl00_MainContentPlaceHolder_txtPONo'');

            var myOption = new Option();
            myOption.text = document.getElementById(''ctl00_MainContentPlaceHolder_txtPONo'').value; //Textbox''s value
            myOption.value = document.getElementById(''ctl00_MainContentPlaceHolder_txtPONo'').value; //Textbox''s value
            ListBox.add(myOption);
            document.getElementById(''ctl00_MainContentPlaceHolder_txtPONo'').value = '''';
        }
    }
</script>



我在服务器端的按钮单击事件:



And my button click event on server side :

protected void btnRemoveFromList_Click(object sender, EventArgs e)
        {
            try
            {
                while (lstPONo.Items.Count > 0)
                {
                    lstPONo.Items.Remove(lstPONo.SelectedItem);
                }
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
            }
        }



我找不到我要去哪里了.
请帮忙,

谢谢,
Lok ..



I cant find out, where I am going wrong.
Please help,

Thanks,
Lok..

推荐答案


<input type="hidden" name="added_to_list" id="added_to_list" value=""></input>



2.在将表单提交到服务器之前,请在隐藏的输入字段中填充添加到客户端列表框中的项目.在条目之间使用一些定界符.

3.在服务器上,阅读隐藏的输入字段,以检索添加的项目,并在定界符处进行分隔.



2. Before submitting the form to the server, populate the hidden input field with the items added to the list box at client side. Use some delimiter between entries.

3. On the server, read the hidden input field to retrieve the added items, separating on the delimiter.



这篇关于从列表框中删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 19:28