Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

12 Experts available now in Live!

Get 1:1 Help Now