Reputation: 2207
I have a little issue with the WebApp I'm building. I have a DropDownList(productddl) which is populated from a DB. OnSelectedIndexChanged for the first dropdown I have a second DropDownList(versionddl) which is populated based on the SelectItem.Value of the first productddl.
After binding productddl I inserted a "Select Product" like so:
productddl.Items.Insert(0, new ListItem(" - Select Product - ", "0"));
The issue is that for example, I select a product the first time and if I try to change it after it adds a second " - Select Product - " to the dropdown. If I keep changing the product it keeps adding and adding.
How can I prevent this from happening? Any help will be really appreciated.
Below is how the productddl is being loaded/populated
if (!IsPostBack)
{
productddl.DataSource = db_GetSet.isp_GetSingle("PRODTCKT", "", "");
productddl.DataTextField = "pr_product";
productddl.DataValueField = "pr_product";
productddl.DataBind();
productddl.Items.Insert(0, new ListItem(" - Select Product - ", "0"));
}
Below is the OnSelectedIndexChanged:
protected void getversion_OnSelect(object sender, EventArgs e)
{
if (!IsPostBack)
{
versionddl.DataSource = db_GetSet.isp_GetMulti("VERDDLV", productddl.SelectedItem.Value, "");
versionddl.DataTextField = "vr_version";
versionddl.DataValueField = "vr_version";
versionddl.DataBind();
productddl.Items.Insert(0, new ListItem("Select Product", "0"));
}
}
Upvotes: 0
Views: 176
Reputation: 3332
Remove productddl.Items.Insert(0, new ListItem("Select Product", "0"));
in the OnSelectedIndexChanged method.
Upvotes: 2