Add Item Manually in DropDownList

In ASP.NET, we can bind the dropdownlist to a data source so that it can display the items dynamically. But one of the problem is that you can’t add the any new item such as “Select One” in the list. But here is the workaround for it:

<asp:DropDownList ID="ddlProducts" DataSourceID="SqlDataSource2" DataTextField="ProductName" runat="server" onDataBound="ddlProducts_DataBound">
</asp:DropDownList>

protected void ddlProducts_DataBound(object sender, EventArgs e)
{
ddlProducts.Items.Insert(0, new ListItem("Select.......","-1"));
}

Leave a Reply