July 08, 2006

Master Detail Update Issue, Resolved

For those of you who have had a problem in ASP.NET 2.0 using a Master Detail setup, (example: gridview as master and detailsview as details):

If you're having trouble getting the GridView to show changes after updating the Details then here's your solution. You're doing the DataBind() command on the GridView (which would rebind the data) in the wrong place. The correct area is: DetailsView1_ItemUpdated as shown below.

Protected Sub DetailsView1_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs) Handles DetailsView1.ItemUpdated

GridView1.DataBind()

End Sub



The reason for this, I believe, is that the databind must be called prior to other page events. It makes sense because you should rebind the datasource when the details are updated. Enjoy!

kick it on DotNetKicks.com

No comments: