如何在选择模式为多个时限制ASP.NET ListBox选择。 [英] How to limit ASP.NET ListBox selection while its selection mode is multiple.

查看:66
本文介绍了如何在选择模式为多个时限制ASP.NET ListBox选择。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,



我使用数据库中的数据在页面代码中绑定ListBox。我已将其选择模式设置为多个。但是我必须禁止Listbox被选中更多的3个值。



我花了很多时间在谷歌但没用,请帮帮我。



谢谢,

解决方案

好吧,如果我用搜索词asp.net listbox multiple selection maximum [ ^ ],前几个帖子本身很有前途和指导性。请看看并告诉我们您尝试过的内容。



如果您仍然卡住,请回来,有人会尽力帮助解决您的问题。

我强烈建议您检查一下您的UI设计。此控件实际上旨在表示从0到N项的任意选择,其中N是项的总数。当您尝试破坏此设计时,该组件将强烈抵制。更糟糕的是,如果你成功了,对于通常期望默认和合理行为的用户来说会太混乱。



我认为至少一个更合理的设计几乎是显而易见的。而不是有一个列表框,有一组组合框。更好的是,在节点上使用带有组合框的类 System.Web.UI.WebControls.TreeView 的实例是理想的。您只需要设置属性 ShowCheckBoxes 并使用属性 CheckedNodes



请参阅:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview%28v=vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.showcheckboxes%28v=vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.checkednodes%28v=vs.110 %29.aspx [ ^ ]。



现在,您想限制支票数量。您需要处理事件 TreeNodeCheckChanged 。创建一些其他控件并显示检查状态,例如检查3个值中的0个,检查3个值中的1个......检查3个值中的3个。它将为用户提供一些反馈,显然将允许有限数量的检查。始终允许取消选中,但阻止检查超出限制的更多节点。



-SA


Hello All,

I am binding ListBox in code behind page using data from database. I have set its selection mode to be multiple. However I have to inhibit Listbox from getting selected more that 3 values.

I spent a lots of time on google but no use, Please help me out.

Thanks,

解决方案

Well, if I look at Google with the search term asp.net listbox multiple selection maximum[^], the first few post themselves are promising and directive enough. Please have a look and show us what you have tried.

If you are still stuck, come back and someone will try to help you with your issue.


I would strongly advise you to review your UI design instead. This control is really designed to represent arbitrary selection from 0 to N items, where N is the total number of items. When you try to break this design, the component will strongly resist. Worse, if you succeed, it will be way too confusing to the users who usually expect default and reasonable behavior.

I think at least one more reasonable design is nearly obvious. Instead of having a list box, have a set of combo boxes. Even better, it would be ideal to use an instance of the class System.Web.UI.WebControls.TreeView with combo-boxes on nodes. All you would need is to set the property ShowCheckBoxes and use the property CheckedNodes:

Please see:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.showcheckboxes%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.checkednodes%28v=vs.110%29.aspx[^].

Now, you want to limit the number of checks. You will need to handle the event TreeNodeCheckChanged. Create some other control and display the checking status, for example "0 of 3 values checked", "1 of 3 values checked"… "3 of 3 values checked". It will provide the user with some feedback, it will become apparent that limited number of checks would be allowed. Always allow unchecking, but block checking more nodes above your limit.

—SA


这篇关于如何在选择模式为多个时限制ASP.NET ListBox选择。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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