views:

4821

answers:

5

Hi,

How to dynamically bind data to <%Html.Dropdownlist.... in asp.net MVC?

Regards, Ambika

+11  A: 

Just pass the correct IEnumerable as the typed model or ViewData. Try something like this (out of my head):

<%= Html.DropDownList(string.Empty, 
    "myDropDownList",  
    new SelectList((IEnumerable)ViewData["stuff"], 
        "DescriptionProperty", 
        "ValueProperty")) 
%>

With that drop down list helper in MVC, you do not really "bind" data to it in the way it is done in the old ASP.NET.

hangy
A: 

thanks man i search about it long time :)

A: 

cN I FOUND THE SOURCE CODE TO EXAMPLE HOW TO BIND dropdownlist FROM MVC

+1  A: 

link textThe link below provides 2 methods to bind dropdownlist. Bind Dropdownlist

A: 

hi i am shivani.i m having problm in drop down list,the items added in d aspx page are nt adding in drop down list at run time.they are being displayed but at the side of drop down list and not inside it.soplease help me asap.

shivani