0
votes

I'm writing a custom field for Sitecore and I want a list box. Interestingly, when I create a Lisbox() and add it to the screen, what actually appears is a combo box. Any idea if Sitecore actually provides a Listbox? And, if so, how I would set multi/single select on it (although that may become obvious to me after I get the correct control to show up)?

I am creating it like this:

Listbox lstResults = new Listbox
{
   ID = GetID("lstResults"),
   Multiple = false,
   Width = Unit.Pixel(300),
   Click = "OnSelectionChanged"
};
2
What does a listbox look like and where is the Listbox class you mention? - Mark Ursino
The Listbox I am using is located in Sitecore.Web.UI.HtmlControls, This appears on the screen as a standard combo box. It does not look like an actual list box. - birdus
Visually, what should a list box look like? I'm asking because I cannot be pictures to words here. - Mark Ursino

2 Answers

1
votes

I realize this thread is a year old, however, as with normal html "option" controls, you can specify a "size" attribute that will cause it to look how you want. For instance, Size=5 will show 5 items in a listbox with a scrollbar for any extras.

I'm not sure if this was added within the past year though.

0
votes

Sitecore doesn't appear to have an actual listbox control, but you can either output a literal (i.e., an HTML control), or, as I did, you can use an ASP.NET ListBox control, with a little tweaking. It's a little more work than using an ASP.NET control normally because Sitecore seems to always want to interfere with things, but it's doable. In this case, just use the normal SelectionMode property to indicate whether to allow multi-select or not.