• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1118
  • 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.
0
canuckconsulting
Asked:
canuckconsulting
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>
     </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
 
OriNetworksCommented:
If you do not assign a width for the dropdownlist it should automatically adjust the width to meet the longest string
0
 
canuckconsultingAuthor Commented:
It did...I foolishly did not see I was constraining the width upstream in css.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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