ASP MVC Set RadioButton From Database

Posted by Jacob Huggart on Stack Overflow See other posts from Stack Overflow or by Jacob Huggart
Published on 2010-05-18T16:19:07Z Indexed on 2010/05/18 16:20 UTC
Read the original article Hit count: 447

Filed under:
|
|

Hello All,

I have what should be an easy question for you today.

I have two radio buttons in my view:

Sex: <%=Html.RadioButton("Sex", "Male", true)%> Male <%=Html.RadioButton("Sex", "Female", true)%> Female

I need to select one based on the value returned from my database. The way I am trying to do it now is:

ViewData["Sex"] = data.Sex; //Set radio button

But that is not working. I have tried every possible combination of isChecked properties. I know that data.Sex is returning either "Male" or "Female". What do I need to do to check the appropriate radio button?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about radiobutton