Depending Dropdowns
<%@ Page Language="vb" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Depending Dropdowns</title>
</HEAD>
<script runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
countryList.Items.Clear()
countryList.Items.Add(New ListItem("- Make a selection -"))
countryList.Items.Add(New ListItem("A", "B"))
countryList.Items.Add(New ListItem("B", "F"))
End If
End Sub
Private Sub SelectedIndexChangedEventHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)
cityList.Items.Clear()
If countryList.SelectedItem.Value = "B" Then
cityList.Items.Add(New ListItem("A1"))
cityList.Items.Add(New ListItem("A2"))
cityList.Items.Add(New ListItem("A3"))
ElseIf countryList.SelectedItem.Value = "F" Then
cityList.Items.Add(New ListItem("B1"))
cityList.Items.Add(New ListItem("B2"))
cityList.Items.Add(New ListItem("B3"))
End If
End Sub
</script>
<body>
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="countryList" runat="server" AutoPostBack="True" OnSelectedIndexChanged="SelectedIndexChangedEventHandler"></asp:DropDownList>
<asp:DropDownList id="cityList" runat="server"></asp:DropDownList>
</form>
</body>
</HTML>
Related examples in the same category