asp:DropDownList追加新项目

来源:百度知道 编辑:UC知道 时间:2024/09/22 03:38:27
<asp:DropDownList ID="iType" runat="server">
<asp:ListItem Selected="True" Value="1">a</asp:ListItem>
<asp:ListItem Value="2">b</asp:ListItem>
</asp:DropDownList>
//我想当页面载入时向"iType"中追加新项目,用代码iType.Items.Add("")不好使,或者用别的什么方法?

protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text.Trim().Length == 0)
{
Response.Write("输入需要添加的item");
}
else
{
DropDownList1.Items.Add(TextBox1.Text);

}
}