asp.net ListBox取消选择项目 [英] asp.net ListBox deselect item

查看:131
本文介绍了asp.net ListBox取消选择项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用asp:ListBox,并且我了解要取消选择项目,用户需要在单击选定项目时按住控制键.有没有一种方法可以使单击选定的项目而无需按住控制键将其取消选择呢?

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?

推荐答案

您可以,但不能在ASP.Net中使用.您需要更改客户端HTML,这意味着您需要使用Javascript对其进行编码,以更改默认行为或选择框.像这样:

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>

但是...我真的建议反对.为了实现您想要的功能,您的"MyHandle"功能必须模仿普通形式所做的一切:选择,取消选择,范围选择(使用移位),单选而不影响其他功能(控制键)等.

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.

如Jakob建议的那样,切换到复选框更容易.

Its easier to switch to checkboxes, as Jakob suggested.

这篇关于asp.net ListBox取消选择项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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