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)
{
dvOrders.ChangeMode(e.NewMode);
if (e.NewMode != DetailsViewMode.Insert)
{
RefreshOrderDetails();
}
}
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)
{
UpdateOrder();
e.Cancel = true;
dvOrders.ChangeMode(DetailsViewMode.ReadOnly);
RefreshOrderDetails();
}
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.
hi, Javier
ReplyDeleteThank 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:
chpz1980@hotmail.com
chpz1980@gmail.com
Javier,
ReplyDeleteThank you so much for this clever solution.
God bless you..
:))
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!
ReplyDeleteProtected Sub DetailsView1_ModeChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewModeEventArgs) Handles DetailsView1.ModeChanging
DetailsView1.ChangeMode(e.NewMode)
If e.NewMode <> DetailsViewMode.Insert Then
Dim intIndex As Integer
intIndex = CInt(CType(DetailsView1.FindControl("lblIndexDV"), Label).Text)
LoadDataList(intIndex)
End If
End Sub
Try handling your LoadDataList(index) via DetailsView.ItemInserting() event.
ReplyDeletehttp://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.detailsview.iteminserting.aspx
Hey, that was very helpful, Thanks!
ReplyDeleteI still have a 3rd problem... When i click the "Cancel" button after clicking "Edit", it's not working
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.
ReplyDelete