Peter M.
Peter M.

Reputation: 1098

How to change width of html.DropDownListFor()

I have small design question about

html.DropDownListFor() 

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

Thanks for answers

Upvotes: 11

Views: 39875

Answers (4)

Mick
Mick

Reputation: 161

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" }

Upvotes: 2

h.boulla
h.boulla

Reputation: 21

In C# you need add @, like this:

new { @style = "width: 350px;" }

Upvotes: 2

iLemming
iLemming

Reputation: 36264

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

Will do the thing. Although better to use css class

Upvotes: 12

griegs
griegs

Reputation: 22770

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" })%>

Upvotes: 16

Related Questions