C# ASP.NET 中的多选下拉列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/774587/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 00:40:14  来源:igfitidea点击:

Multi-select dropdown list in ASP.NET

c#asp.netweb-controls

提问by Jan Remunda

Do any good multi-select dropdownlist with checkboxes (webcontrol) exist for asp.net?

asp.net 是否存在带有复选框(webcontrol)的多选下拉列表?

Thanks a lot

非常感谢

采纳答案by knut

You could use the System.Web.UI.WebControls.CheckBoxListcontrol or use the System.Web.UI.WebControls.ListBoxcontrol with the SelectionModeproperty set to Multiple.

您可以使用该System.Web.UI.WebControls.CheckBoxList控件或使用属性设置为的System.Web.UI.WebControls.ListBox控件。SelectionModeMultiple

回答by Jason Coyne

HTML does not support a dropdown list with checkboxes. You can have a dropdown list, or a checkbox list. You could possibly fake a dropdowncheckbox list using javascript and hiding divs, but that would be less reliable than just a standard checkbox list.

HTML 不支持带有复选框的下拉列表。您可以使用下拉列表或复选框列表。您可能会使用 javascript 和隐藏 div 伪造下拉复选框列表,但这不如标准复选框列表可靠。

There are of course 3rd party controls that look like a dropdown checkboxlist, but they are using the div tricks.

当然,也有看起来像下拉复选框列表的 3rd 方控件,但它们使用了 div 技巧。

you could also use a double listbox, which handles multi select by moving items back and forth between two lists. This has the added benefit of being easily to see all the selected items at once, even though the list of total items is long

您还可以使用双列表框,它通过在两个列表之间来回移动项目来处理多选。这有一个额外的好处,即可以轻松地一次查看所有选定的项目,即使总项目列表很长

(Imagine a list of every city in the world, with only the first and last selected)

(想象一下世界上每个城市的列表,只选择第一个和最后一个)

回答by JP Alioto

I like the Infragistics controls. The WebDropDownhas what you need. The only drawback is they can be a bit spendy.

我喜欢基础设施控制。该WebDropDown有你需要的东西。唯一的缺点是它们可能有点浪费。

回答by Aleris

jQuery Dropdown Check Listcan be used to transform a regular multiple select html element into a dropdown checkbox list, it works on client so can be used with any server side technology:

jQuery Dropdown Check List可用于将常规的多选 html 元素转换为下拉复选框列表,它适用于客户端,因此可以与任何服务器端技术一起使用:

alt text
(source: googlecode.com)

替代文字
(来源:googlecode.com

回答by Richard Xiong

Here's a cool ASP.NET Web control called Multi-Select List Field at http://www.xnodesystems.com/. It's capable of:

这是http://www.xnodesystems.com/ 上的一个很酷的 ASP.NET Web 控件,名为 Multi-Select List Field 。它能够:

(1) Multi-select; (2) Auto-complete; (3) Validation.

(1) 多选;(2) 自动完成;(3) 验证。

回答by Maxim Saplin

Try this server control which inherits directly from CheckBoxList (free, open source): http://dropdowncheckboxes.codeplex.com/

试试这个直接从 CheckBoxList(免费,开源)继承的服务器控件:http: //dropdowncheckboxes.codeplex.com/

回答by Mick Bruno

I've used the open source control at http://dropdowncheckboxes.codeplex.com/and been very happy with it. My addition was to allow a list of checked files to use just file names instead of full paths if the 'selected' caption gets too long. My addition is called instead of UpdateSelection in your postback handler:

我使用过http://dropdowncheckboxes.codeplex.com/ 上的开源控件并且对它非常满意。我的补充是,如果“选定”标题太长,则允许检查文件列表仅使用文件名而不是完整路径。在回发处理程序中调用我的添加而不是 UpdateSelection:

// Update the caption assuming that the items are files<br/> 
// If the caption is too long, eliminate paths from file names<br/> 
public void UpdateSelectionFiles(int maxChars) {
  StringBuilder full = new StringBuilder(); 
  StringBuilder shorter = new StringBuilder();
  foreach (ListItem item in Items) { 
    if (item.Selected) { 
      full.AppendFormat("{0}; ", item.Text);
      shorter.AppendFormat("{0}; ", new FileInfo(item.Text).Name);
    } 
  } 
  if (full.Length == 0) Texts.SelectBoxCaption = "Select...";
  else if (full.Length <= maxChars) Texts.SelectBoxCaption = full.ToString(); 
  else Texts.SelectBoxCaption = shorter.ToString();
}