asp.netdropdowndetailsview

Adding Item at first Index of Database-bound DropdownList in DetailsView


I have a DetailsView on an ASP-Webform with several DropdownLists bound to ForeignKey-Tables. I want to add something like "Please choose..." at the first index of Items. I´m using DataBound-Event of Dropdown to add this ListItem with the shown Text and Value = 0. But the "Please choose..."-Item is always at the last index of the Items.

How can I do to get it at the first Index?


Solution

  • You can write

    ddl.Items.Insert(0,new ListItem("Please Choose","0"));

    ddl is your DropDownList ID