tags:

views:

40

answers:

1

Hi

I am wondering how we can set the width of the Dropdown. When i write the below line of code, I am getting compilation error.

<%= Html.DropDownList("product", ViewData["product"], new { style = "width: 300px;"})%>

Appreciate your responses.

+2  A: 
<%= Html.DropDownList("product", (SelectList) ViewData["product"], new { style = "width: 300px;"})%>

because I think ViewData["product"] is considered as object so its thinks it is the overload html attributes

Gregoire
This problem goes away altogether if you use the best practice of using a strongly typed ViewModel instead of ViewData.
Keith Rousseau
This worked. Thanks.
Rita
@Rita - Please accept this answer if it solved your issue!
curtisk