views:

396

answers:

1

I have a master/details setup with a GridView and DetailsView both in UpdatePanels. When the DetailsView is edited and updated, I want these changes to be reflected in the GridView, but without rebinding that data (which could change the selectedItem's sort order among other problems it causes) On DetailsView ItemUpdated I have the following:

    ' Update Gridview '
    ProductsGridView.Rows(selectedIndex).Cells(1).Text = e.NewValues("ProductName")
    ProductsGridView.Rows(selectedIndex).Cells(2).Text = e.NewValues("Category")

This works fine when updating, but when a new item is selected in the Gridview, the updated text disappears. Why is this and how can I keep that info? When it is rebound it is fine if it changes position, put until it gets re-bound I would like that data to persist. Thanks.

+1  A: 

Answer: It was because the cell's text was not being stored in the viewstate. I added Literal controls to hold the cell's text and updated the literal's text accordingly instead of using the cell's text, like so:

        ' Update Gridview '
    CType(ProductsGridView.Rows(selectedIndex).FindControl("thisLit"), Literal).Text = e.NewValues("SomeValue")
    CType(ProductsGridView.Rows(selectedIndex).FindControl("someOtherLit"), Literal).Text = e.NewValues("OtherValue"))

The information is now kept in viewstate and works perfectly =)

Ryan