Search code examples
asp.netdynamic-data

Add "Select" item in DropDown


I am using ASP.NET dynamic data. In Insert.aspx page, I have a couple of dropdowns to be selected. The fields represented by Dropdown are Required fields in database. So dropdown does not show 'Select' as default option in dropdown. I want to add 'Select' option at top of other records from database shown in dropdown. Note that field is not Required field, hence 'Select' option is not being show over there by dynamic data by default. How can I accomplish this?


Solution

  • Add your "select" item after binding your dropdownlists by using Insert method :

    myDropDownList.DataBind();
    // To make it the first element at the list, use 0 index : 
    myDropDownList.Items.Insert(0, new ListItem("Select", string.Empty));