views:

416

answers:

2

Hello,

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?

+6  A: 

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".

David Stratton
will try do this now
Chicago
Good idea +1 for you.......
Muhammad Akhtar
easy way to highlight selected items? without javascript
Chicago
+2  A: 

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.

despart
I'm voting this up because it should work, and there may be reasons for using a ListBox as opposed to a CheckBoxList. Can you provide some sample javascript code?
David Stratton