Dirk Dot Net

Creator of useful things. Based in Chiang Mai, Northern Thailand.

Using DetailsView to insert when the DataSet is Empty

Scott Mitchell has what is probably the smoothest solution for the GridView which works for the DetailsView just the same:

  1. Put a DetailsView into the EmptyDataTemplate of the "parent DetailsView"
  2. Bind it to the same datasource as the parent
  3. Set the DefaultMode of the child to "Insert"

Alternatively, you can put a Button into the EmptyDataTemplate and define the click event handler as follows:

protected void Button1_Click(object sender, EventArgs e)  
{
DetailsView1.ChangeMode(DetailsViewMode.Insert); 
}