Multi-select dropdown list in ASP.NET
Asked Answered
L

8

37

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

Thanks a lot

Lubricant answered 21/4, 2009 at 21:1 Comment(0)
M
39

You could use the System.Web.UI.WebControls.CheckBoxList control or use the System.Web.UI.WebControls.ListBox control with the SelectionMode property set to Multiple.

Merilee answered 21/4, 2009 at 21:12 Comment(2)
i used CheckBoxList and TextBox. Showing and hiding it with javascript and absolute positioning.Lubricant
@Jan Remunda can you give detailed javascript for that? I would appreciate it!Smegma
O
28

jQuery Dropdown Check List can 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:

alt text
(source: googlecode.com)

Octameter answered 11/7, 2009 at 17:11 Comment(3)
I think this solution is just what the question asked for! Very solid alternative!Resect
But in C# codebehind, how would we access the checked list? with the accepted answer we can use foreach(ListItem li in listBox1.Items){if(li.Selected){myList.Add(listItem.Text); } }Oscitant
@Oscitant the transformation is purely visual. In the serverside, this can still be a regular asp:ListBox control (and yes, I'm aware that I'm replying to a nearly 10 year old question lol).Underthrust
C
6

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

Conundrum answered 30/5, 2011 at 14:57 Comment(0)
P
3

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:

// 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();
} 
Predestine answered 3/7, 2011 at 1:22 Comment(0)
C
1

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.

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

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)

Costplus answered 21/4, 2009 at 21:6 Comment(0)
E
1

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

Endear answered 21/4, 2009 at 21:8 Comment(0)
L
1

Check this out. It's free one.

http://irfaann.blogspot.com/2009/07/ajax-based-multiselect-dropdown-control.html

HTH,

Labiovelar answered 11/7, 2009 at 17:5 Comment(2)
This post was flagged as spam and downvoted, but the control appears to be nice and it IS free, so it gets my upvote. Maybe irfan can give you some free technical support in exchange for the link. :)Nne
Agreed. This was probably blocked by many peope's websense filter which is such a stupid thing to have to concern my time with when I could be solving important problems.Eponymy
K
0

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

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

Kegler answered 12/8, 2010 at 0:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.