i have a Drop-down list which is data bounded from a table and i want to remove an item from it on page load, but the problem is nothing is happening from this piece of code:
on page load:
protected void Page_Load(object sender, EventArgs e)
{
ListItem itemToRemove = DropDownList1.Items.FindByText("compiler"); //just want to remove this value
if (itemToRemove != null)
{
DropDownList1.Items.Remove(itemToRemove);
}
}
**dropdownlist code on aspx page**:
<asp:DropDownList ID="DropDownList1" AppendDataBoundItems="true" runat="server" DataSourceID="SqlDataSource1" DataTextField="qpname" DataValueField="qpname" Height="16px" Width="116px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True">
<Items>
<asp:ListItem Text="Select" Value="" />
</Items>
</asp:DropDownList>
the sqldata source code on aspx page:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:projectConnectionString %>" SelectCommand="SELECT [qpname] FROM [A1_quespapers]"></asp:SqlDataSource>
Note : dropdownlist is displaying the all bounded values including value to be deleted (compiler) - image here