Setting the C# ASP.NET DetailsView control in Edit modus, trigger the DataBound event for the DetailsView control, and in this event handler populate a DropDownList and finally set the
SelectedValue of that DropDownList to the value of the underlying data. This might seem fairly easy, but there is a lot of confusion about it. Now here's the very basic guide to programmatically setting the default value for a DropDownList in a DetailsView control.
You need a detailsview control into the HTML-part (name it DetailsView1 in the .aspx file) and use templated fields, and somehow bind that control to data. You also need to set the
OnDataBound event in the detailsvei control. Set it to point to a method in your code behind file (aspx.cs). Example:
OnDataBound="DetailsView_Databound". And finally you need a DropDownList inside the
EditItemTemplate of your choice.
protected void DetailsView_Databound(Object sender, EventArgs e)
if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
DropDownList dropper = (DropDownList)DetailsView1.FindControl(
if (dropper != null)
dropper.SelectedIndex = dropper.Items.IndexOf(