birdus
birdus

Reputation: 7514

Sitecore custom field listbox

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"
};

Upvotes: 0

Views: 621

Answers (2)

Keith D Ball
Keith D Ball

Reputation: 131

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.

Upvotes: 1

birdus
birdus

Reputation: 7514

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.

Upvotes: 0

Related Questions