RowDeleted 后 GridView PreRender 未触发

发布于 2024-10-08 05:58:26 字数 1160 浏览 0 评论 0原文

当删除 UI 中的 GridView 行(通过其 CommandName="Delete" 的 LinkBut​​ton)时,视图不会自动刷新并继续显示已删除的行,直到我采取其他操作(手动刷新页面、导航离开并再次返回, ETC)。

在调试器中,我看到该行已成功删除,并且 RowDeleting 和 RowDeleted 事件均触发,但 GridView 的 PreRender 事件随后不会触发(相反,PreRender 事件在首次加载时确实触发)页面,添加新行时等)。

我在类似的配置中使用了 GridView,没有遇到此问题,但我没有看到明显的差异。看起来该过程在 PreRender 事件之前中止,但没有引发异常,并且在调试器中退出 RowDeleted 事件的末尾使我返回到 UI,就像该过程正常完成一样。

我应该在哪里寻找问题或解决方案有什么想法吗?其他可能相关的细节:GridView 绑定到 SqlDataSource;数据源没有声明任何DeleteCommand;我通过在 RowCommand 处理程序中调用存储过程来处理删除,然后使用 DataBind() 重新绑定 GridView,此时我可以看到 GridView 的 Rows.Count 已按我的预期减少了 1。通过 RowDeleted 事件,一切看起来都很好,然后……什么也没有!

更新:尝试在 RowDeleting 处理程序而不是 RowCommand 处理程序中调用 SP 进行删除...没有什么区别。该行仍会被删除,但处理会在不调用 GridView 的 PreRender 的情况下终止,并且删除的行将继续显示,直到进一步的 UI 交互更新视图。

UPDATE2:我什至没有获得页面的 PreRender 事件,该事件先于控件 PreRender 事件。将继续向后工作,看看我是否能找到停止的地方,因为走出 RowDeleted 事件似乎是行的末尾...

UPDATE3:我一直在探索更多,尽管它使我的代码变得复杂,我能够通过在 GridView 的 SqlDataSource 中声明一个删除命令来完成简单的行(记录)删除,然后在 RowDeleted 处理程序中调用我的存储过程中需要与初次删除。虽然在一个地方进行主要删除并在另一个地方进行相关处理不太方便,但至少它是有效的。

但我不知道从中得出什么结论:正确的页面生命周期需要删除命令吗?不应该在 RowCommand 处理程序中的存储过程中执行删除操作吗?还有什么吗?我希望我能确定我最初的尝试具体有哪些问题......

When deleting a GridView row in the UI (via a LinkButton whose CommandName="Delete"), the view does not automatically refresh and continues to display the deleted row until I take some other action (manually refresh page, navigate away and back again, etc).

In the debugger, I see the row is successfully deleted, and both the RowDeleting and RowDeleted events fire, but the GridView's PreRender event does not fire afterwards (in contrast, that PreRender event does fire when first loading the page, when adding a new row, etc).

I've used GridViews in similar configurations without having this problem, but I don't see obvious differences. It seems the process is aborting before the PreRender event, but no exceptions are being thrown, and stepping off the end of the RowDeleted event in the debugger brings me back to the UI as though the process were completing normally.

Any ideas where I should look for the trouble or a solution? Other possibly-relevant details: the GridView is bound to a SqlDataSource; the data source does not declare any DeleteCommand; I handle the deletion by calling a stored procedure in the RowCommand handler, after which I rebind the GridView with DataBind(), at which point I can see the GridView's Rows.Count has decreased by one as I'd expect. Everything seems fine through the RowDeleted event, then... nothing!

UPDATE: tried calling the SP to delete in the RowDeleting handler rather than RowCommand handler... made no difference. The row is still deleted but processing terminates without calling the GridView's PreRender, and the deleted row is left on display until some further UI interaction updates the view.

UPDATE2: I'm not even getting the Page's PreRender event, which precedes the control PreRender events. Will continue working backwards to see if I can find where things are halting, since stepping out of the RowDeleted event seems to be the end of the line...

UPDATE3: I've been poking around some more and, although it complicates my code, I was able to get things working by declaring a DeleteCommand in the GridView's SqlDataSource that just does the simple row (record) deletion, and then in the RowDeleted handler calling the additional stuff I had in my stored procedure that needs to happen along with the primary deletion. While it's less convenient having the primary deletion in one place and the related processing in another, at least it's working.

But I don't know what to conclude from this: that a DeleteCommand is needed for proper page life cycle? that one shouldn't do a deletion in a stored procedure in the RowCommand handler? something else? I wish I could identify what, specifically, is broken about my initial attempt...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

星軌x 2024-10-15 05:58:27

删除行后,只需将 gridview 与数据库中的新数据绑定即可。

just bind the gridview with the fresh data from database after deleting the row.

↘人皮目录ツ 2024-10-15 05:58:27

PreRender 事件是否会在其他页面的回发时触发? 这篇 MSDN 文章 中的信息(在“回发和非回发”部分下)服务器控件中的事件”标题,注释后面的段落)让我想知道是否页面和所有子控件都会触发 Init 和 Load 事件。

Do PreRender events fire on postbacks on your other pages? The information on this MSDN article (under the "Postback and Non-Postback Events in Server Controls" heading, paragraph after the note) makes me wonder if only the Init and Load events fire for the page and all child controls.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文