0

I have a marital status field in my users table that its just varchar yet I only want to give the users four options (married, single, widowed and divorced) and i want to have the correct one selected when Im editing the form.. is it possible? please help.

1
  • Of course it is possible. Can you show us what you have that is not working? Commented Feb 3, 2010 at 14:39

2 Answers 2

2

This should point you in the right direction:

<%= Html.DropDownList("listName", new string[] { "Married", "Single", "Widowed", "Divorced" }
.Select(m => new SelectListItem(){
    Selected = model.MaritalStatus == m,
    Text = m,
    Value = m
})); %>

Assuming that your model has a 'MaritalStatus' field,

Selected = model.MaritalStatus == m

will select the status of your model by default.

Sign up to request clarification or add additional context in comments.

Comments

0

This blog post should lead you in the right direction:

http://weblogs.asp.net/ashicmahtab/archive/2009/03/27/asp-net-mvc-html-dropdownlist-and-selected-value.aspx

you'd have to give us a little more information and maybe a code sample of what you have so far to get a more specific answer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.