我在數據庫表中有兩列,一個是國家,另一個是端口。在插入時從下拉列表中選擇國家相關端口加載到列表框中。 然後我們選擇一個國家的多個端口並插入數據庫。檢索下拉列表中的多個值
Eg. Country:-India Port:-AGARTALA,BAGDOGRA,BANGALORE,COIMBATORE
表視圖是這樣的。現在我需要檢索所有插入表中下拉列表中的所有端口。如何解決...在此先感謝。
我在數據庫表中有兩列,一個是國家,另一個是端口。在插入時從下拉列表中選擇國家相關端口加載到列表框中。 然後我們選擇一個國家的多個端口並插入數據庫。檢索下拉列表中的多個值
Eg. Country:-India Port:-AGARTALA,BAGDOGRA,BANGALORE,COIMBATORE
表視圖是這樣的。現在我需要檢索所有插入表中下拉列表中的所有端口。如何解決...在此先感謝。
首先,你需要分割你的數據:
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
}));
});
你需要幫助嗎哪一部分這個問題與? – axlj
現在我已經添加了5個國家和港口相關的國家現在我有五行端口名稱與多個端口用逗號分隔現在我需要加載下拉所有端口 – sarode111
明白了。因此,有三部分內容:查詢數據庫,將數據加載到.NET中的對象中,最後將數據返回給客戶端。你堅持哪部分? – axlj