• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1147
  • Last Modified:

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

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.
1 Solution
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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>

     <span id="hidnSpan">



        $('#sel').width( $('#hidnSpan').html($('#sel').find(":selected").text()).width())


Open in new window

If you do not assign a width for the dropdownlist it should automatically adjust the width to meet the longest string
canuckconsultingAuthor Commented:
It did...I foolishly did not see I was constraining the width upstream in css.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now