[英]Retrieve data from database column in WebMatrix
Im using WebMatrix 2. I need retrieve data from column in my database. 我正在使用WebMatrix 2.我需要从我的数据库中的列中检索数据。 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! 提前致谢!
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.