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

Discussion in 'ASP .Net Web Controls' started by DOK, Mar 2, 2007.

  1. DOK

    DOK Guest

    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);
     
    DOK, Mar 2, 2007
    #1
    1. Advertising

  2. On 2 Mar., 17:52, "DOK" <> wrote:
    > 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.
     
    Henrik Stidsen, Mar 6, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Miller [msft]

    Re: Code Behind vs. no code behind: error

    Ben Miller [msft], Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    607
    Alphonse Giambrone
    Jun 28, 2003
  2. Chumley Walrus
    Replies:
    1
    Views:
    12,189
    =?Utf-8?B?QnJpYW4gQnJvd24=?=
    Dec 16, 2004
  3. John

    Non-code behind to code behind

    John, Feb 19, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    499
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 19, 2007
  4. Peter S.

    Composite dropdownlist control that also displays a listbox????

    Peter S., Nov 21, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    168
    Peter S.
    Nov 21, 2005
  5. Peter S.

    Custom dropdownlist that displays a listbox

    Peter S., Nov 21, 2005, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    119
    Peter S.
    Nov 21, 2005
Loading...

Share This Page