Solved

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

Posted on 2011-09-19
4
252 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now