ListBox created in code-behind displays as DropDownList???

D

DOK

I am dynamically creating a series of ListBoxes and populating them in
code-behind. If I set the SelectionMode to single, the controls render
as DropDownLists, which is not what I want. If I change the
SelectionMode to Multiple, I get the ListBox that I want.

Is there a way to force the ListBox to appear as a ListBox? It's
declared as a ListBox, but what I'm getting is a DropDownList.

Here's an example of the code I'm using to set the ListBox properties:
ListBox rowsList = (ListBox)lists;
rowsList.AutoPostBack = true;
rowsList.EnableViewState = true;
rowsList.ID = "RowsList1";
rowsList.Rows = 1;
rowsList.SelectedIndexChanged += new
EventHandler(RowsList_Click);
rowsList.SelectionMode = ListSelectionMode.Multiple;
rowsList.Width = Unit.Pixel(150);
 
H

Henrik Stidsen

rowsList.Rows = 1;

Try setting this one to 2 or higher. A listbox with a height of 1 and
selectionmode single will be displayed as a dropdownbox. You might be
able to change the height of the rendered control with CSS.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top