views:

130

answers:

2

How can I set a select class and other attributes eg:events through the SelectList object?

If this cannot be done, what are the best practices in populating a select input (dropdownlist) ie should I just loop through the items and render the <option> tags

I guess events should be bound to the controls in jquery for instance, but I do need the class forto do this.

+1  A: 
<%=Html.DropDownList("elementname",yourSelectList,"defaultvalue",new{@class="yourclass"}) %>
Gregoire
+1  A: 

The htmlAttributes parameter should take an anonymous type initialised like this :

new {@class="some-css-class"}

Gary W