Solved

Any way to get dropdownlist's list to drop down?

Posted on 2011-09-19
4
254 Views
Last Modified: 2012-08-13
Is there any way to get a dropdownlist control to display its list automatically when a page is loaded?  To "unfurl", so to speak?
0
Comment
Question by:Alastair_White
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
geowrian earned 500 total points
ID: 36564673
A normal drop down list? No. The controls are built into the client's browser, and no method exists to make them "drop down".

As an alternative, if you built your own pseudo-drop down list using divs and unordered lists and CSS, you could hide/show that div. But it's not a simple procedure and not native to ASP.NET.
0
 
LVL 16

Expert Comment

by:disrupt
ID: 36564832
Check this thread:

http://stackoverflow.com/questions/2048213/open-select-using-javascript-jquery

you can change the size which will list everything:

   





<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#<%= DropDownList1.ClientID %>").attr('size', 5);
    });
  </script>
 
<asp:DropDownList ID="DropDownList1" runat="server">
         <asp:ListItem>Item 1</asp:ListItem>
         <asp:ListItem>Item 2</asp:ListItem>
         <asp:ListItem>Item 3</asp:ListItem>
         <asp:ListItem>Item 4</asp:ListItem> 
         <asp:ListItem>Item 5</asp:ListItem> 
    </asp:DropDownList>

Open in new window

0
 
LVL 12

Expert Comment

by:geowrian
ID: 36564987
@disrupt
That's a smart idea for some options, but it's not really simulating a click of a drop down list. It's basically treating the drop down list as a multiline <select> object, which means it loses the visual drop-down aspects when the size attribute is > 1. If the list contains lots of items, it will show all of them at once (unlike a drop down list), it takes up multiple display lines (i.e. putting it in a table with many options would make all other cells push downward), etc. You can fight some of these using a number of javascript functions and some CSS (i.e. upon click convert it back to a drop-down list, use absolute positioning and z-indexes, etc.) as noted in the URL you referenced. However, it's not pretty and may not look or function as expected across browsers and/or versions (especially IE 6/7/8).

I just wanted to point out that detail - it's visually not the same as a drop down list so I wanted the OP to be aware of that.
0
 

Author Closing Comment

by:Alastair_White
ID: 36567731
Alright, that's what I wanted to know.  I am new to asp.net and even new to HTML, and I have no clue about javascript or CSS or anything.  Total noob, trying to go the easiest route.  I will work around this.  Thanks for the info.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question