简体   繁体   English

如何在多次点击时保留列表框选定的项目值?

[英]How to retain listbox selected items values on multiple clicks?

for (int i = 0; i < lboxavilableInsName.Items.Count; i++)
{
    if (lboxavilableInsName.Items[i].Selected)
    {
        if (!arraylist1.Contains(lboxavilableInsName.Items[i]))
        {
            arraylist1.Add(lboxavilableInsName.Items[i]);
            arrUpdatedInsValues.Add(lboxavilableInsName.Items[i].Value);
            arrUpdatedInsNames.Add(lboxavilableInsName.Items[i].Text);                          
        }
        ViewState["UpdatedInsValues"] = arrUpdatedInsValues;
        arrUpdatedInsValuestotal = (ArrayList)ViewState["UpdatedInsValues"];
        ViewState["UpdatedInsValues2"] = `enter code here`arrUpdatedInsValuestotal;
        ViewState["UpdatedInsNames"] = arrUpdatedInsNames;
    }
}

Actually I have given selsectionmode="Multiple" in the listbox. 实际上我在列表框中给出了selsectionmode="Multiple" That will select me multiple items when I select first time or subsequent time after page gets loaded, but I want that in a code behind saying ex: if I select 2 items 1st time that 2 items will added in the second listbox and I will get the values of those selected items. 当我选择加载页面后第一次或后续时间选择我会选择多个项目,但是我想在代码后面说ex:如果我选择2项第一次在第二个列表框中添加2个项目我会得到这些选定项目的值。

If again I select any items after adding previous selection items in 2nd listbox , I want the item value selected at 2nd time along with first two item values. 如果我在第二个listbox添加先前的选择项后再次选择任何项目,我希望第二次选择项目值以及前两个项目值。 So totally 3 values I want. 所以我想要的总共3个值。 and I need to send that values to the stored procedure to insert. 我需要将该值发送到要插入的存储过程。

Its because you are assigning new values each time to the 2nd listbox, you don't need to assign them, you need to add values within your 2nd listbox, in this way your 2nd listbox will retain all the previous and the new values as well. 这是因为您每次都要为第二个列表框分配新值,您不需要分配它们,您需要在第二个列表框中添加值,这样您的第二个列表框将保留所有以前的值和新值。 Hope it helps. 希望能帮助到你。

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

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