how to display selected value in drop down list in asp.net mvc?

Posted by Renu123 on Stack Overflow See other posts from Stack Overflow or by Renu123
Published on 2010-05-18T13:24:43Z Indexed on 2010/05/18 13:30 UTC
Read the original article Hit count: 201

Filed under:

i want to display selected value in drop down list . the value comes from the data base. for ex suppose we want to update user profile then value for gender which is previously provided by the user should get displayed as selected value. the code that i used to display is

<% string val = Convert.ToString(Model.gender);
   ViewData["gen"] = val; 
%>
<%= Html.DropDownList("genderList", ViewData["gen"] as SelectList) %>

but its not showing the value from the database.but viewdata get value from database but it is not showing on drop down list. thanks in advance.

© Stack Overflow or respective owner

Related posts about asp.net-mvc