2012-07-28 93 views
0

我正在使用SQL Server實施地理位置表。
我在數據庫中添加了主要國家,州和城市,但我希望允許通過在下拉列表中選擇'其他'選項來添加值。如果我在國內選擇'其他',則應在州和城市下拉菜單中選擇相同的選項。它還應該爲每個下拉菜單顯示額外的文本框。
我使用的是asp.net 3.5,數據庫是使用linq的sql server 2008。請幫忙!!在asp.net中的下拉列表中選擇「其他」選項添加新城市

回答

0

你從數據庫中值填補你的下拉菜單後,你應該增加一個:「其他...」與「其他」的價值,它應該被放置在列表的末尾。
此外,你應該把一個隱藏的文本框爲每個下拉:

<asp:TextBox ID="txtState" runat="server" Style="display:none;"></asp:TextBox> 

在客戶端,你可以使用jQuery或JavaScript趕上當用戶選擇該值。應該有三個功能:「其他國家」顯示所有三個文本框,「其他國家」展示了兩個和「其他城市」只有一個顯示:

$('#countries').change(function() { 
    var country= $("#states option:selected").text(); 
    if(country == 'other') { 
     var country = $("#countries option:selected").val(); 
    if (country === 'other') { 
     $("#states").val('other'); 
     $("#cities").val('other'); 

     $("#txtCountry").show(); 
     $("#txtState").show(); 
     $("#txtCity").show(); 
    } 
    else { 
     //if user select 'other' and later select something else, you should hide textbox 
     $("#txtCountry").hide(); 
    } 

}); 

以同樣的方式,對國家和城市創建功能。

之後,在後面的代碼中,您可以檢查選定的值是否是「其他」,然後使用文本框中的值。我希望你明白這個主意。

+0

嘿,謝謝你的回覆....我明白了......! – Sushant 2012-08-01 06:09:00

0
$('#states').change(function() { 
    alert('Handler for .change() called.'); 
    var value = $(this).val(); 
     if(value == '') 
     { 
     // change other city drop down 
     var newOption = $('<option value="">Other</option>'); 
     $('#city').append(newOption); 
     } 
}); 
相關問題