How to change width of html.DropDownListFor()
Asked Answered
L

4

11

I have small design question about

html.DropDownListFor() 

How can I change width of html.DropDownListFor() ?? For example by css.

Thanks for answers

Lollygag answered 15/6, 2010 at 22:22 Comment(0)
M
16

Have you tried Html.DropDownListFor( new {width:"100"})

or Html.DropDownListFor( new {@class:"longDropdownList"})

EDIT

<style>
    .MakeWide { width: 200px; }
</style>

<%= Html.DropDownListFor(x => x.Name, new SelectList(new List<string>()), new { @class = "MakeWide" })%>
Moreau answered 15/6, 2010 at 22:24 Comment(1)
@Peter M, see my edit. I have tested this and it works. If it doesn't work on yours then we have another type of problem. Possibly another style is setting the width of all <select input boxes.Moreau
S
12

@Html.DropDownListFor(x => x.Name, new SelectList(new List<string>()), new {style="width:270px;"} );

Will do the thing. Although better to use css class

Splotch answered 14/3, 2011 at 18:12 Comment(1)
This works for me to adjusting the width. However, how to change the height? I tried to add "width=270px;height=50px" and see no effect on height, why?Fonda
G
2

In C# you need add @, like this:

new { @style = "width: 350px;" }
Georgetta answered 12/12, 2013 at 15:47 Comment(1)
In C# you only need the @ symbol for reserved words. Style is not a reserved word in C# and therefore doesn't need it.Lewse
L
2

If you are using Bootstrap it sets the max width to 280px in site.css.

You probably don't want to change that so to override it for individual controls set:

new { style = "max-width:100%;width:350px" }
Lewse answered 22/12, 2021 at 14:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.