Reputation: 66573
So I have an ASP.NET page with two controls:
GridView
which displays rows from a SqlDataSource
, and in which the user can select a row;DetailsView
in which the user can see and edit the values of the selected row.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
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