2012-07-28 97 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); 
     } 
}); 
相关问题