Reputation: 1381
Im using WebMatrix 2. I need retrieve data from column in my database. This is database column:
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:
But I need obtain this result:
I tried many solutions, without success. Thanks in advance!
Upvotes: 1
Views: 595
Reputation: 30110
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>
Upvotes: 3