C# 以编程方式向DropDownList添加选项

C# 以编程方式向DropDownList添加选项,c#,asp.net,drop-down-menu,visual-web-developer,C#,Asp.net,Drop Down Menu,Visual Web Developer,我在ASP.NET的一个网站上工作,遇到了一个问题。当在另一个下拉列表中选择新选项时,我希望网站将选项添加到一个下拉列表中。为此,我使用第二个下拉列表的SelectedIndexChanged事件。当我通过将此行添加到此事件中来测试代码时: DropDownSubject.Items.Add("TEST"); 第一个下拉列表没有任何变化。是不是因为这个下拉列表在编辑器中自动写入了单词“Unbound”?我如何解决这个问题 下面是第一个下拉列表的标记,我想将项目添加到其中: <asp:Dr

我在ASP.NET的一个网站上工作,遇到了一个问题。当在另一个下拉列表中选择新选项时,我希望网站将选项添加到一个下拉列表中。为此,我使用第二个下拉列表的SelectedIndexChanged事件。当我通过将此行添加到此事件中来测试代码时:

DropDownSubject.Items.Add("TEST");
第一个下拉列表没有任何变化。是不是因为这个下拉列表在编辑器中自动写入了单词“Unbound”?我如何解决这个问题

下面是第一个下拉列表的标记,我想将项目添加到其中:

<asp:DropDownList ID="DropDownClasses" runat="server" 
                >

第二个,我正在使用事件:

<asp:DropDownList ID="DropDownSubject" runat="server" 
                onselectedindexchanged="DropDownSubject_SelectedIndexChanged">
                <asp:ListItem>Mathematics</asp:ListItem>
                <asp:ListItem>Foreign Language</asp:ListItem>
                <asp:ListItem>Science</asp:ListItem>
                <asp:ListItem>Social Studies</asp:ListItem>
                <asp:ListItem>English</asp:ListItem>
            </asp:DropDownList>

数学
外语
科学类
社会科学课程
英语

非常感谢所有帮助。

详细信息:听起来您没有为第一个下拉列表设置自动回邮功能。下面的例子

  <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" 
    AutoPostBack="true">
        <asp:ListItem>Cat</asp:ListItem>
        <asp:ListItem>Dog</asp:ListItem>
  </asp:DropDownList>

<asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>

“第一个下拉列表没有任何变化”是什么意思?这是否意味着SelectedIndexChanged事件未触发,或者SelectedIndexChanged正在触发,但无法添加项目?请显示两个下拉列表的标记。似乎既没有触发事件,也没有将项目添加到下拉列表中。
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    DropDownList2.Items.Add(DropDownList1.SelectedItem.Text);
}