如何在多次点击时保留列表框选定的项目值? [英] How to retain listbox selected items values on multiple clicks ?

查看:103
本文介绍了如何在多次点击时保留列表框选定的项目值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在列表框上多次点击时保留列表框项目...多次点击会有多个值会知道...但我只得到最后一次点击选定的值...但我需要所有选中的项目值多次点击....



感谢你



我的尝试:



how to retain listbox items on multiple clicks on list box...on multiple clicks there will be multiple values will get know...but i am getting only last click selected value...but i need all selected item values of multiple clicks....

thanking you

What I have tried:

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"] = arrUpdatedInsValuestotal;
                       ViewState["UpdatedInsNames"] = arrUpdatedInsNames;
                   }

推荐答案

您需要更新 SelectionMode 属性为多个,以确保用户可以从列表中选择多个值。这个的默认值是Single,这就是你所看到的,因为你只选择了最后一个。

You need to update the SelectionMode property to Multiple to ensure that the users can select multiple values from the list. The default value for this is Single and that is what you are seeing as you only get the last one as selected.
<asp:ListBox id="ListBox1" runat="server" SelectionMode="Multiple">
     <asp:ListItem Value=".89">apples</asp:ListItem>
     <asp:ListItem Value=".49">bananas</asp:ListItem>
</asp:ListBox>



代码取自以下MSDN页面,您可以在自己的代码中试用。如果我理解正确,您可能需要按住 CTRL 键来选择多个值; 或者ASP.NET Web Forms也可以存储



ListBox.SelectionMode属性(System.Web.UI.WebControls) [ ^ ]

us / library / system.web.ui.webcontrols.listselectionmode(v = vs.110).aspx> ListSelectionMode枚举(System.Web.UI.WebControls ) [ ^ ]


The code was taken from the following MSDN pages, you can try it out in your own code. If I understand correctly you might require to hold CTRL key to select multiple values; or maybe ASP.NET Web Forms stores that as well.

ListBox.SelectionMode Property (System.Web.UI.WebControls)[^]
ListSelectionMode Enumeration (System.Web.UI.WebControls)[^]


这篇关于如何在多次点击时保留列表框选定的项目值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆