如何解决如何基于另一个 DropDownList 在 DropDownList 中添加值
我有两个下拉列表:第一个是员工类别(A、B、C、D),另一个是员工姓名(为简单起见,假设 John 和 Adam 在 A 级,Marry 和 Mike 在 B 级) .要做到这一点:
<%@ Page Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Salary.aspx.cs" Inherits="Employees.Salary" %>
<asp:Content ContentPlaceHolderId="ContentPlaceHolder1" runat="server">
Employee class: <asp:DropDownList ID="drpmonth" runat="server" OnSelectedindexChanged="meth" >
<asp:ListItem>SELECT</asp:ListItem>
<asp:ListItem>A</asp:ListItem>
<asp:ListItem>B</asp:ListItem>
<asp:ListItem>C</asp:ListItem>
<asp:ListItem>D</asp:ListItem>
</asp:DropDownList> <br />
Employee name: <asp:DropDownList ID="DropDownList2" runat="server" AutopostBack="True">
<asp:ListItem>SELECT</asp:ListItem>
</asp:DropDownList>
</asp:Content>
<script runat="server">
protected void meth(object sender,EventArgs e)
{
if(drpmonth.SelectedValue == "A")
{
DropDownList2.Items.Add("Adam");
DropDownList2.Items.Add("John");
}else if(drpmonth.SelectedValue == "B")
{
DropDownList2.Items.Add("Marry");
DropDownList2.Items.Add("Mike");
}
}
</script>
但这不起作用!你知道我的代码有什么问题吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。