问题
I'm usting an asp:ListBox
and I understand that to deselect items the user needs to hold down control while clicking on a selected item. Is there a way to make it that clicking on a selected item will deselect it without holding down control?
回答1:
You can, but not in ASP.Net. You need to change the client-side HTML, meaning you need to code it using Javascript, to change the default behaviour or a select box. Something like:
<script>
function MyHandle(oSelect)
{
(change behaviuor here, using object oSelect)
return false;
}
</script>
<SELECT onclick="MyHandle(this)">
...
</SELECT>
But... I really recomend against it. To acheive what you want, your "MyHandle" function would have to emulate everything that normal forms does: selecting, de-selecting, range selecting (using shift), single selection without affecting others (control key), etc.
Its easier to switch to checkboxes, as Jakob suggested.
回答2:
I don't think asp.net's listbox can do that out of the box (I think winform's listbox can) but you can set SelectionMode to Multiple and write javascript to achieve the behavior you require.
来源:https://stackoverflow.com/questions/5373610/asp-net-listbox-deselect-item