Results 1 to 5 of 5

Thread: DropDownList - limit number of lines shown

  1. #1

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    DropDownList - limit number of lines shown

    Is it possible to limit number of lines being shown in the drop down list? Example, If I have 200 lines being filled I only want 10 lines to show and then use scrolldown to view the entire list. Thank you.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: DropDownList - limit number of lines shown

    The DropDownList asp.net control generates a <select> html element which has a size attribute which indicates the number of visible elements.

    You can add the attribute to the DropDownList control.

    <aspropDownList ID="DropDownList1" runat="server" Size="10" >

    Visual Studio will indicate that Size is not an attribute of the DropDownList but this is just informational, the attribute gets written in the final html. eg

    <select name="DropDownList1" id="DropDownList1" Size="10">

    You could also add the Size attribute at runtime.

    Code:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        DropDownList1.Attributes.Add("Size", "10")
    End Sub
    Last edited by brucevde; Sep 19th, 2008 at 11:31 AM.

  3. #3

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    Re: DropDownList - limit number of lines shown

    Hi brucevde,

    That seems to do the trick. I need to set the size at the time when user clicks the down arrow and then display the number of lines I want. I tried to find the event for this, is there any? Thank you for your help.
    Last edited by snufse; Sep 19th, 2008 at 02:53 PM.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: DropDownList - limit number of lines shown

    Why do you need to do it when the select element is clicked? Do you want to change the size dynamically at runtime?

    Also, the size property will make it a 'listbox' rather than limit the number of visible items in the dropdownlist. Is that what you want?

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: DropDownList - limit number of lines shown

    To do it using javascript
    Code:
    <select onclick="this.size=4;">
    <option>sdf</option>
    <option>sdf</option>
    <option>sdf</option>
    <option>sdf</option>
    <option>sdf</option>
    <option>sdf</option>
    <option>sdf</option>
    <option>sdf</option>
    <option>sdf</option>
    <option>sdf</option>
    </select>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width