2016-11-11 59 views
-1

我在數據庫表中有兩列,一個是國家,另一個是端口。在插入時從下拉列表中選擇國家相關端口加載到列表框中。 然後我們選擇一個國家的多個端口並插入數據庫。檢索下拉列表中的多個值

Eg. Country:-India Port:-AGARTALA,BAGDOGRA,BANGALORE,COIMBATORE 

表視圖是這樣的。現在我需要檢索所有插入表中下拉列表中的所有端口。如何解決...在此先感謝。

+0

你需要幫助嗎哪一部分這個問題與? – axlj

+0

現在我已經添加了5個國家和港口相關的國家現在我有五行端口名稱與多個端口用逗號分隔現在我需要加載下拉所有端口 – sarode111

+0

明白了。因此,有三部分內容:查詢數據庫,將數據加載到.NET中的對象中,最後將數據返回給客戶端。你堅持哪部分? – axlj

回答

0

首先,你需要分割你的數據:

var data = 'Country:-India Port:-AGARTALA,BAGDOGRA,BANGALORE,COIMBATORE'; 

var portStart = data.lastIndexOf('-')+1; 

//create an array of items by removing the garbage in the beginning 
//and splitting on the commas 
var ports = data.substr(portStart).split(','); 

然後使用jQuery的$.each()方法來遍歷數組中的所有項目:

// ports -> the array from above 
// function()... the operation to perform on each item in the array 
$.each(ports, function (index, value) { 
    //insert an option element into #ports with the value/text attributes set as shown 
    $('#ports').append($('<option/>', { 
     value: value, 
     text : value 
    })); 
}); 
+0

下拉下載,但如何在數據庫中添加數據中的所有記錄 – sarode111

+0

您的問題需要解決,並且這不是免費的代碼服務。這對你來說至少可以去嘗試一下。 – axlj

+0

好的,我正在努力.. – sarode111