Dropdownlist - number of display element

2019-06-26 01:52发布

问题:

I have dropdownlist on my webpage.

When I click it the list with all items is expanded. But this list is very long.

How can I change it to achievie a list with (e.g.) 5 displayed items and with a scrollbar next to them.

If it is not possible, how can I do it with ListBox? I know it is Rows property there but can I declare how many rows is display all the time not after expanding the list.

回答1:

This control, will, of course be rendered on the page as a standard <select> control.

With these, the height of the list once its dropped down is determined by the browser, and you have no control over this. You'll notice when the list approaches the foot of the page, the browser will implement the scrollbar as you suggested, but not with the number of items you maybe want.

My only suggestion would be to investigate the options offered by some client-side drop down add-ins. You may be able to find some jQuery ones that will help.

A simple google search for "jquery dropdowns" yielded this article as the top result: 38 jQuery And CSS Drop Down Multi Level Menu Solutions. If you can't find something here then there are also plenty similar sites in the search results.



回答2:

I think this post provides you with a couple of different solutions to your problem.

http://blogs.msdn.com/b/rakkimk/archive/2011/05/02/dropdownlist-html-select-vertical-scrollbar-number-of-items.aspx