Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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..
 
Share this answer
 
v2
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900