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.
Printable View
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.
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.
<asp:DropDownList 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
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.
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?
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>