Solved

Asp.Net DropDown list, expand width to show all options on select

Posted on 2014-03-04
3
1,033 Views
Last Modified: 2014-03-07
I have an asp.net project which has a dropdownlist.  I have controlled the width to fit on the form but when the user selects from it I wanted the width to expand to show the entire texts of the available entries.  

It is partially doing this naturally I as shown below I just need it to expand a bit more.  Happy to do this via CSS or js.
0
Comment
Question by:canuckconsulting
3 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 39907060
try this out, since you have jQuery as a tag:

<select id="sel">
         <option value="aaaa">aaaa</option>
         <option value="aaaaaaaa">aaaaaaaa</option>
         <option value="aaaaaaaaaaaa">aaaaaaaaaaaa</option>
         <option value="aaaaaaaaaaaaaaaa">aaaaaaaaaaaaaaaa</option>
         <option value="aaaaaaaaaaaaaaaaaaaa">aaaaaaaaaaaaaaaaaaaa</option>
     </select>

     <span id="hidnSpan">

     <span>

<script>

$(document).ready(function()
{
    $('#sel').change(function()
    {
        $('#sel').width( $('#hidnSpan').html($('#sel').find(":selected").text()).width())
    });
});


</script>

Open in new window

0
 
LVL 17

Accepted Solution

by:
OriNetworks earned 500 total points
ID: 39912470
If you do not assign a width for the dropdownlist it should automatically adjust the width to meet the longest string
0
 

Author Closing Comment

by:canuckconsulting
ID: 39913859
It did...I foolishly did not see I was constraining the width upstream in css.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

792 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