问题描述
如果我绑定的GridView(通过的DataSourceID属性)来SqlDataSource和设置的SelectCommand和更新命令属性,那么一切都完美的作品。
If I bind GridView (via DataSourceID attribute) to SqlDataSource and set SelectCommand and UpdateCommand attributes, then everything works perfectly.
但我注意到,如果我,无论出于何种原因,也可手动调用DataBind()内的Page_Load(),然后SqlDataSource的不执行任何更新,即使SqlDataSource.Updating和SqlDataSource.Updated事件做火的时候GridView的Update按钮被点击。
But I’ve noticed that if I, for whatever reason, also manually call DataBind() inside Page_Load(), then SqlDataSource doesn’t perform any updates, even though SqlDataSource.Updating and SqlDataSource.Updated events do fire when GridView’s Update button is clicked.
有人能解释为什么更新不会发生?
Could someone explain why updates don’t happen?
推荐答案
这是因为在Page_Load被激发的SqlDataSource.Updating BEFORE和SqlDataSource.Updated事件触发。这意味着,在GridView复位到什么是用户编辑之前。
It's because the Page_Load is fired BEFORE the SqlDataSource.Updating and SqlDataSource.Updated events fire. This means that the GridView resets to what it was before the user edits.
请检查href=\"http://msdn.microsoft.com/en-us/library/ms178472.aspx\">页面生命周期的详细信息文档
Please review the Page Lifecycle documentation for details. The SqlDataSource.Updating and SqlDataSource.Updated events happen in the Postback Event Handling section.
这篇关于如果的DataBind()被调用内的Page_Load(),然后SqlDataSource的不执行更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!