Is there a way to control the number of displayed rows in a DropDownList control? I'd like it to only display 10 rows, but it defaults to 30. This causes the list to appear higher than the control instead of below it because of its position on the page.
You can do pagination on the data source for the drop down list using PagedDataSource and set the PageSize to 10.
If ASP.NET renders a DropDownList control as a <select> then there is no way to control the number of rows shown when the <select> is opened, it is browser-implementation dependant.
A quick test shows that IE 6 reveals 27 items from a 27 item list, Safari for Windows 3.2.1 reveals 22, Firefox 2 reveals 20 and Opera 9.6.2 reveals 16. The number revealed may even depend on the total number of items, but I didn't bother to test that because it is pretty obvious this isn't something you're going to be able to control.
Adding size="..." to the control will make the drop-down list a fixed size and it will no longer be a "drop-down list" (assuming you can even do that).
The only solution to this seems to be to implement a JavaScript-based pull-down control of your own, or buy or download one.
Note:
I have not tried this using code
Add "size" attribute with "10" as value to show 10 rows in the dropdown.
<asp:dropdownlist size="10" ...>
Does this work? (I am guessing it,as dropdownlist is SELECT tag in html)
Related
I am running a .net web application on IE10. The issue seems to be with the way the items are being displayed in the dropdownlist. In IE10 if an item is chosen from the list which happens to be in middle (say you are choosing the 3rd item out of 5) and then again click on drop down list then the list spans as 2 elements above this value and 2 below. Also if you choose the very last item and then again click on the drop down the list is displayed as all the items above the last item and then the last item in the field (list is displayed upwards).
So the issue appears when these items are displayed after choosing them and clicking again on the control just to see all the items.
In IE8 and 9 it is like the item chosen is displayed in the field
and then the whole list follows below this.
Please help...
I also meet this problem.
But when I search here, it is said be design. I don't know if it is true, but I couldn't find anyway to fix it.
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.
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.
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
Consider an ASP.NET server control DropDownList (or <input type='select'>) with a large number of options (e.g. 100 options). When clicking on the list, the full list of 100 options are shown. They're all displayed, and run off the screen.
How can the control's picklist size be resized or limited to the first n options?
Frédéric Hamidi has already given the short answer, however he has also referred you to a perfect alternative. Explore this and that is similar to what I had done when I faced similar situation.
Idea is that you don't populate your list. This way your drop down will be empty and in place of that you show a div with scrollbar and whatever you wish. Align this div in such a way that user thinks, "it is the dropdown".
I am using a list view with page size 10 and added a numeric data pager for paging.everything is working fine but how i can hide the page number shown below when the data in list view is less than 10 and show it only data is greater than 10.
pls help me out....
You would attach to PagePropertiesChanged event of the ListView and retrieve the number of items displayed in the current page. If the number is less than 10, set Visible to false of the DataPager.
Sorry for my english.
1) Have a listbox with 3 values out of 5 selected
2) When I click to select another value without holding CTRL button, it will unselect over values
How to make it keep other selected values if new value is selected?
This is going to sound like a snide answer, but I don't mean it that way. I just like to look for the simple solutions rather than the complicated onces.
The easiest way to get a control to have the behavior you want is to use a control that has the behavior that you want, rather than modifying the behavior of an existing control.
That said, if you want a list of items where a user can select a bunch of items off the list, and don't want to have to rely on them holding control, you're using the wrong tool for the job.
Use a CheckBoxList instead of a ListBox. If you want it to be scrollable, then set it in a div of a specific height, and set the style of the div to "overflow: scroll".
If you still want to use a ListBox you should use javascript and for each click event fired, you should check if the clicked element is selected/unselected and act accordingly. It's a little bit tricky but at least it is a solution for your problem.