我有两个DropDownList
级联控件(第二个控件是根据第一个控件的选择填充的):
<asp:DropDownList ID="ddlProduct" runat="server" AppendDataBoundItems="true"
AutoPostBack="true" onselectedindexchanged="ddlProduct_SelectedIndexChanged">
<asp:ListItem Value="" Selected="True"> - Product - </asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlCategory" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="ddlCategory_SelectedIndexChanged" AppendDataBoundItems="true">
<asp:ListItem Value="" Selected="True"> - Category - </asp:ListItem>
</asp:DropDownList>
在ddlProduct.SelectedIndexChanged
事件处理程序中,我有以下代码:
ddlCategory.DataSource = _productService.GetCategoryByProductId(ddlProduct.SelectedValue);
ddlCategory.DataTextField = "CategoryName";
ddlCategory.DataValueField = "CategoryId";
ddlCategory.DataBind();
用户第一次从中选择产品时ddlProduct
已ddlCategory
正确填充。接下来的时间,类别中ddlCategory
的附加到第一次选择的类别,依此类推。我试着输入ddlProduct.SelectedIndexChanged
:
ddlCategory.Items.Clear();
但该方法也删除了硬编码的项目
<asp:ListItem Value="" Selected="True"> - Category - </asp:ListItem>
我怎样才能从 ddlCategory 中删除附加的项目?