If DataBind() is called inside Page_Load(), then SqlDataSource doesn’t perform updates

情到浓时终转凉″ 提交于 2019-12-23 03:00:26

问题


If I bind GridView (via DataSourceID attribute) to SqlDataSource and set SelectCommand and UpdateCommand attributes, then everything works perfectly.

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?


回答1:


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.

Please review the Page Lifecycle documentation for details. The SqlDataSource.Updating and SqlDataSource.Updated events happen in the Postback Event Handling section.



来源:https://stackoverflow.com/questions/1203163/if-databind-is-called-inside-page-load-then-sqldatasource-doesn-t-perform-u

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!