Link to home
Start Free TrialLog in
Avatar of Éric Moreau
Éric MoreauFlag for Canada

asked on

Limit the number of items in a ASP.Net drop down list

I have a situation where a part of a dropdownlist (in ASP.Net) is off the screen.

How can I limit the number of items in a ASP.Net drop down list or how can I set the Maximum height?
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Eric,

I don't know if that is possible to limit that.

Bob
Avatar of ChadFolden
ChadFolden

Limiting the number of items would obviously result in not all the values being shown, which I'm not sure if that's actually what you're wanting or not, but you have a couple options if this is really what you want to do:
1) you could limit the results displayed in your drop down list by filtering the results for the datasource of the drop down (for example: if your dropdown list is database-driven, you could use "select top 10 from yourtbl" or SELECT field from yourtbl WHERE somefilter=somefilter).  
2) When the drop down list is bound (or on pageload) you could loop through the items in the dropdown list and delete() everything past a certain index
Other options might include:
3) Maybe you could use javascript to move the page down a little so that the drop down isn't off the page
4) you could make the font smaller
5) If the list is very long, You could the autocomplete control of the AJAX.net toolkit so that when the user starts typing all those options with that value are shown rather than all

Let me know if you need anymore suggestions .. I'm sure there are more, but these are the first that come to mind.
Good luck
Avatar of Éric Moreau

ASKER

TheLearnedOne, that is what I found after a short google session this afternoon. I hope someone will know a trick or has build a component doing that.

ChadFolden, I don't want to limit the number of total items in my list. I want to reduce the height of the combo. Currently, when it is opening, it shows about 20 items. I would like to limit it to about 12 because on some screen (depending on the user screen resolution), a portion of the drop down is off the screen and is not visible.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
We found the reason to that problem! it only occurs on PC having dual screens when the browser is showing on the one that has the lowest resolution.

We will not fix it for now has only developpers have this setup.