当底层数据发生变化时,GridView内容不会更新 [英] GridView contents don’t update when underlying data changes
问题描述
$ b $ a code GridView 显示来自
SqlDataSource
的行,并且用户可以在其中选择一行; DetailsView
,其中用户可以看到并编辑所选行的值。 DetailsView
可以更新底层数据,但即使页面重新加载, GridView
仍会显示旧的数据,直到我手动在浏览器中重新加载页面。 如何确保 GridView
在 DetailsView
中显示正确的数据?
PS注意由于其他问题中列出的原因可能很重要,我不得不使用自定义的 OnItemUpdating
事件与 DetailsView
。此事件执行SQL更新命令(成功),将 DetailsView
设置回ReadOnly模式(超出编辑模式),然后取消事件( e .Cancel = true
)。如果这个事件取消也以某种方式取消了 GridView
更新,我该如何手动告诉它更新它?
PPS :我发现了类似的问题,但答案并不奏效:它将整个页面重置为原始状态,这意味着 GridView
失去选中的行,并且 DetailsView
消失。我不希望这样。
关于网页加载:
YourGridViewID.DataBind()
So I have an ASP.NET page with two controls:
- a
GridView
which displays rows from aSqlDataSource
, and in which the user can select a row; - a
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.
on page load:
YourGridViewID.DataBind()
这篇关于当底层数据发生变化时,GridView内容不会更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!