ASP:列表框|多选|选择新值时保留所选值

发布于 2024-08-09 15:12:42 字数 131 浏览 0 评论 0原文

1) 有一个列表框,其中选择了 5 个值中的 3 个值

2) 当我单击选择另一个值而不按住 CTRL 按钮时,它将取消选择值

如果选择了新值,如何使其保留其他选定值?

1) Have a listbox with 3 values out of 5 selected

2) When I click to select another value without holding CTRL button, it will unselect over values

How to make it keep other selected values if new value is selected?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愁以何悠 2024-08-16 15:12:42

这听起来像是一个讽刺的答案,但我并不是那个意思。我只是喜欢寻找简单的解决方案而不是复杂的解决方案。

使控件具有所需行为的最简单方法是使用具有所需行为的控件,而不是修改现有控件的行为。

也就是说,如果您想要一个项目列表,其中用户可以从列表中选择一堆项目,并且不想依赖它们来控制,那么您使用了错误的工具来完成这项工作。

使用 CheckBoxList 而不是 ListBox。如果希望它可以滚动,那么将其设置在特定高度的div中,并将div的样式设置为“overflow:scroll”。

This is going to sound like a snide answer, but I don't mean it that way. I just like to look for the simple solutions rather than the complicated onces.

The easiest way to get a control to have the behavior you want is to use a control that has the behavior that you want, rather than modifying the behavior of an existing control.

That said, if you want a list of items where a user can select a bunch of items off the list, and don't want to have to rely on them holding control, you're using the wrong tool for the job.

Use a CheckBoxList instead of a ListBox. If you want it to be scrollable, then set it in a div of a specific height, and set the style of the div to "overflow: scroll".

梦一生花开无言 2024-08-16 15:12:42

如果您仍然想使用 ListBox,则应该使用 javascript,并且对于触发的每个单击事件,您应该检查单击的元素是否被选择/取消选择并采取相应的操作。这有点棘手,但至少它是您问题的解决方案。

If you still want to use a ListBox you should use javascript and for each click event fired, you should check if the clicked element is selected/unselected and act accordingly. It's a little bit tricky but at least it is a solution for your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文