1

Im using WebMatrix 2. I need retrieve data from column in my database. This is database column:

enter image description here

I have used this code to retrieve data and get it in combobox

@{ var db1 = Database.Open("StarterSite"); var selectCommand = "SELECT Motivo FROM Set_Residenziali"; var selectedData = db1.Query(selectCommand); } <select name="motivo"> @foreach(var row in selectedData) { <option value="@row.Motivo">@row.Motivo</option> } </select> 

With this code I get this result:

enter image description here

But I need obtain this result:

enter image description here

I tried many solutions, without success. Thanks in advance!

1 Answer 1

3

You need to split the value:

<select name="motivo"> @foreach(var row in selectedData){ foreach(var item in row.Motivo.ToString().Split(new [] {','})){ <option>@item</option> } } </select> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.