Click here to Skip to main content
14,328,524 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,
I working under asp.net with c# platform, the total project's design was completed, now i want to apply the autowidth to dropdownlist, forexample, dropdown should fit for small string and for large string also, can u help me regarding this.
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

Just remove width from DropdownList and by default it will be auto. Make sure any other CSS don't affect it. If it's the case, you can simply add style="width:auto;".

Regards..
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

use this

1. Adding the style=width:auto; into the ASP.NET webcontrol, as mentioned in the question.

2. Adding element.Attributes.Add('style', 'width:auto'); in the code behind. Generally it is the same as option number 1, just that it's added from code behind. But option 1 seems to be better because it does not mix presentation with code behind, and changing the presentation does not require recompiling of the program.

3. Remove the Width property for the ASP.NET control. If the Width property is not specified, it will be set as auto. But here we need to be careful if there is any CSS rule that may affect the behavior, for example we specify input in the CSS file
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100