Timwi
Timwi

Reputation: 66573

GridView contents don’t update when underlying data changes

So I have an ASP.NET page with two controls:

The DetailsView can update the underlying data, but even though the page reloads, the GridView still displays the old data until I manually reload the page in the browser.

How do I ensure that the GridView displays the correct data after the update in the DetailsView?

P.S. It may be important to note that due to reasons outlined in this other question, I had to use a custom OnItemUpdating event with the DetailsView. This event performs the SQL update command (successfully), sets the DetailsView back to ReadOnly mode (out of Edit mode) and then cancels the event (e.Cancel = true). If this event canceling also somehow cancels the GridView updating, how do I manually tell it to update itself?

P.P.S.: I discovered this similar question, but the answer doesn’t work: it resets the entire page back to pristine state, which means the GridView loses its selected row and the DetailsView disappears. I don’t want that.

Upvotes: 2

Views: 1859

Answers (2)

rofans91
rofans91

Reputation: 3010

If your OnItemUpdating event generates postback

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        GridView.DataBind();//rebinding it with considering changes DetailView
    }
}

If it doesn't work let me know.

Upvotes: 0

boruchsiper
boruchsiper

Reputation: 2028

on page load:

YourGridViewID.DataBind()

Upvotes: 3

Related Questions