我使用asp.net VB 我想要做的是有2個下拉框在asp.net VB
有一點麻煩的第一個下拉列表值填充第二個下拉菜單中的第一個下拉將有 1例如。
如果1選擇我想第二個下拉自動選擇c中的第二個下拉將有 一個 b c。通過默認 ..但
。 我不知道JavaScript是否是最好的答案,或者如果有人曾經這樣做過,我會非常感謝你的建議。 謝謝!
我使用asp.net VB 我想要做的是有2個下拉框在asp.net VB
有一點麻煩的第一個下拉列表值填充第二個下拉菜單中的第一個下拉將有 1例如。
如果1選擇我想第二個下拉自動選擇c中的第二個下拉將有 一個 b c。通過默認 ..但
。 我不知道JavaScript是否是最好的答案,或者如果有人曾經這樣做過,我會非常感謝你的建議。 謝謝!
您可以在服務器端或Java腳本中執行此操作。一般的概念是相同的。您必須定位第一個下拉列表的「更改」事件中的第二個下拉列表。這意味着每當第一個變化事件觸發,則在更新第二個
須藤代碼:
Dropdown1_Changed()
{
//if "1" is selected in Dropdown1, update Dropdown2 to select "c"
}
我會proboby第一個下拉列表使用SelectedIndexChanged事件。就像這樣:
ASPX
<asp:DropDownList ID="ddl1" runat="server" AutoPostBack="true">
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddl2" runat="server">
<asp:ListItem Text="A" Value="A"></asp:ListItem>
<asp:ListItem Text="B" Value="B"></asp:ListItem>
<asp:ListItem Text="C" Value="C"></asp:ListItem>
</asp:DropDownList>
VB
Private Sub ddl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl1.SelectedIndexChanged
If ddl1.SelectedValue = "1" Then
ddl2.SelectedValue = "C"
End If
End Sub
您可以使用JavaScript onChange事件。
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function NumbersDropDownList_OnChange() {
var numbersDropDownList = document.getElementById("numbersDropDownList");
if (numbersDropDownList.options[numbersDropDownList.selectedIndex].text=="1") {
document.getElementById("lettersDropDownList").selectedIndex = 2;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="numbersDropDownList" onchange="NumbersDropDownList_OnChange()" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="lettersDropDownList" runat="server">
<asp:ListItem>a</asp:ListItem>
<asp:ListItem>b</asp:ListItem>
<asp:ListItem>c</asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>