2013-05-02 73 views
1

使用WebMatrix 2的我需要从数据库的列中检索数据。这是数据库列:从WebMatrix的数据库列中检索数据

enter image description here

我已经使用这个代码来检索数据,并把它在组合框中

@{ 
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> 

有了这个代码,我得到这样的结果:

enter image description here

但我需要获得这个结果:

enter image description here

我尝试了很多解决方案,但没有成功。提前致谢!

回答

3

您需要拆分值:

<select name="motivo"> 
    @foreach(var row in selectedData){ 
     foreach(var item in row.Motivo.ToString().Split(new [] {','})){ 
     <option>@item</option> 
     } 
    } 
</select>