在vb.net的列表框中限制选择 [英] limit selections in a listbox in vb.net

查看:139
本文介绍了在vb.net的列表框中限制选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在vb.net中创建一个包含列表框的Web控件.我知道我可以选择单选"或多选"选择模式,但是我有兴趣将多选"限制为预定大小.例如,阻止用户选择3个以上的项目.

I am creating a web control in vb.net that contains a list box. I know that I am able to choose a selection mode of Single or Multiple, but I am interested in limiting a Multiple selection to a predetermined size. For example preventing a user from selecting more than 3 items.

我试图将验证器添加到列表框中,这可能是一种前进的方式,但是我想知道是否存在一种将选择模式更改为与两个指定模式不同的方法.

I have tried adding a Validator to the list box, which might be a way forward, but was wondering if there was a way of changing the selection mode to something a bit different than just the two specified ones.

任何想法或建议将不胜感激

Any ideas or suggestions would be greatly appreciated

不幸的是,由于项目限制,我无法在此问题上使用Javascript.我知道很烦人!

Unfortunately due to project limitations I am unable to use Javascript on this problem. very annoying I know!

推荐答案

您可以尝试处理SelectedIndexChange事件之一.使用多项选择,每次触发此事件时,您都可以检查已经选择了多少项.如果超出您的期望,请让处理程序取消选择刚刚选择的那个.您还可以在列表框下方添加一个红色标签,上面写着对不起,最多允许[n]个选择."

You could try handling one of the SelectedIndexChange events. With multiple selection, each time this event fires you can check how many items have already been selected. If it is more than you want, have the handler deselect the one that was just selected. You could also put up a little red label under the listbox saying "Sorry, no more than [n] selections allowed."

刚注意到您说的是WEB.同样的理论也适用,但是必须使用Javascript来完成.

Just noticed you said WEB. Same theory applies, but it would have to be done using Javascript.

这篇关于在vb.net的列表框中限制选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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