Limit selection in a list in vb.net

I am creating a web control in vb.net containing a list. I know that I can choose Single or Multiple selection mode, but I'm interested in limiting multiple selection to a given size. For example, prevent the user from selecting more than three items.

I tried adding Validator to the list box, which might be a way forward, but I wondered if there was a way to change the selection mode to something other than the two specified.

Any ideas or suggestions are welcome.

Edit: Unfortunately, due to project limitations, I cannot use Javascript to solve this problem. very annoying, I know!

+3
source share
2 answers

You can try to handle one of the SelectedIndexChange events. With multiple selections, each time this event fires, you can check how many items are already selected. If this is more than you want, ask the handler to deselect the selected object. You can also put a small red mark in the list, saying "Sorry, no more than [n] is valid."

EDIT: Just noticed that you said WEB. The same theory applies, but it will need to be used with Javascript.

+2
source

SelectedIndexChanged , , , ( , , ).

0

Source: https://habr.com/ru/post/1703109/


All Articles