We help IT Professionals succeed at work.

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

4,891 Views
Last Modified: 2013-11-07
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?
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
Eric,

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

Bob
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
Éric MoreauSenior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016

Author

Commented:
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.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Éric MoreauSenior .Net Consultant
CERTIFIED EXPERT
Top Expert 2016

Author

Commented:
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.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.