Tuesday, March 18, 2008

DetailsView Edit Mode never changes after Update command. DetailsView Edit button requires to clicks to change to edit mode.

I was stocked for sometime using the asp.net 2.0 DetailsView control to Edit/Update data. I wanted to do my custom implementation for the Update command instead of using the DataBinding Object sources but I found my self in trouble with several road blocks.

Problem 1:
When clicking on the Edit button the DetailsView will not change the mode until the second click. The edit button required two clicks to change the mode to Edit instead of ReadOnly.
I solved this problem by changing the mode in the ModeChanging event handler and then rebinding the DetailsView control.

ModeChanging Event Handler:

protected void dvOrder_ModeChanging(object sender, DetailsViewModeEventArgs e)

if (e.NewMode != DetailsViewMode.Insert)

Problem 2:
When clicking the update button I handle the updating of the order in the ItemUpdating event but the ItemUpdated never fires and the DetailsView never change the mode to ReadOnly after the data was updated. DetailsView control always stayed on the Edit Mode.

I solve this problem by canceling the ItemUpdating event, changing the mode, and rebinding the details view data source.

ItemUpdating Event Handler:

protected void dvOrder_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)


e.Cancel = true;



This was the only way I got things to worked for me. The ItemUpdated event never fired but I got the DetailsView to works how I wanted. I wish there was an easier way to do this or at least more documentation on Microsoft’s website.


  1. hi, Javier
    Thank this text, it help me to deal with some problems which i meet.
    I am a developer for .net.
    Do you make friends with me and discuss some skill problems.
    Thank you.

    contact me:

  2. Oxygen and Mete5/01/2008 8:56 AM


    Thank you so much for this clever solution.

    God bless you..


  3. Help! I tried the solution you suggested, but still have to click the "edit" button twice for it to go into edit mode. Here's my piece of VB code. Any thoughts? Thanks!

    Protected Sub DetailsView1_ModeChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewModeEventArgs) Handles DetailsView1.ModeChanging

    If e.NewMode <> DetailsViewMode.Insert Then
    Dim intIndex As Integer
    intIndex = CInt(CType(DetailsView1.FindControl("lblIndexDV"), Label).Text)
    End If

    End Sub

  4. Try handling your LoadDataList(index) via DetailsView.ItemInserting() event.


  5. The blog is helpfull...
    visit also asp.net [c#]

  6. Hey, that was very helpful, Thanks!

    I still have a 3rd problem... When i click the "Cancel" button after clicking "Edit", it's not working

  7. Hey I was wondering if you could just help me.....I know XQuery is XML Query....but what is JQuery????????? Please provide information over it. Provide links to related topics if possible.