I am currently working with the WebForms
framework and I have encountered an issue with my dropdownlist
control in one of my Forms. The Select
option is sometimes being added twice, causing duplication in my form. I am looking for a way to either remove this duplicate option or hide it altogether.
I attempted to track how many times the Select
option is being added and then hide it, but unfortunately, my attempts were not successful.
The reason behind this issue seems to be that the method grdview_Color_DataBound
is getting called twice.
https://i.sstatic.net/2ya9n.png
<select name="ctl00$MainContent$grdview_Color$ctl10$ddl_Grd_Color" id="MainContent_grd_ddl_grdview_Color" class="form-control dropdown">
<option value="0" selected="selected" disabled="disabled">Select</option>
<option value="0" disabled="disabled">Select</option>
<option value="Yellow">Yellow</option>
<option value="Red">Red</option>
<option value="Blue">Blue</option>
<option value="Green">Green</option>
</select>
protected void grdview_Color_DataBound(object sender, EventArgs e)
{
ListItem firstItem = new ListItem("Select", "0");
firstItem.Attributes.Add("disabled", "disabled");
ddl.DataSource = dataSource;
ddl.DataTextField = TextField;
ddl.DataValueField = ValueField;
ddl.DataBind();
ddl.Items.Insert(0, firstItem);
}