2013-05-02 50 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>