Search code examples
drop-down-menusharepoint-2007

How to add empty alternative to drowpDownList


I am populating dropdownlist like this:

SPList categories = SPContext.Current.Web.Lists["Categories"];
                dropdownlist.DataSource = categories.Items;
                dropdownlist.DataValueField = "ID";
                dropdownlist.DataTextField = "Title";
                dropdownlist.DataBind();

Let say, if user do not want to select any value from dropdownlist, but want to select an empty option. how i add an empty alternative to dropdownlist ??


Solution

  • Add this line after you populate the ddl

    dropdownlist.Items.Add(new ListItem("Select Value", "0"));