简体   繁体   English

gridview更新后执行方法

[英]Execute method after gridview update

I have a GridView that makes use of an ObjectDataSource that references a class that updates, creates, deletes and views info, each in its own method that calls a stored procedure to do the desired operation. 我有一个GridView ,它使用ObjectDataSource引用一个类来更新,创建,删除和查看信息,每个类都以其自己的方法来调用存储过程以执行所需的操作。 I also have a hidden control on the page that holds a set of Id's that i send to the SELECT method in the class that is used in the stored procedure to load the data. 我在页面上还有一个隐藏的控件,该控件包含一组ID,这些ID将发送给存储过程中用于加载数据的类中的SELECT方法。

I set the value of this hidden control in the Page_Load event. 我在Page_Load事件中设置了此隐藏控件的值。 This means that if I update a field in the GridView (ie changing one of the ID's) the control still has the old set of ID's. 这意味着,如果我更新GridView的字段(即更改ID之一),则控件仍具有旧的ID集。 I need to run the method in my code-behind after the GridView is updated in order to load the correct new results. 为了加载正确的新结果,在更新GridView之后,我需要在代码背后运行该方法。

I've been debugging and noticed that the SELECT method in the class connected to the ObjectDataSource is called just after the UPDATE method in the same class. 我一直在调试,注意到连接到ObjectDataSource的类中的SELECT方法在同一类中的UPDATE方法之后调用。 How can I call a method in the code-behind just before this SELECT ? 如何在SELECT之前的代码后面调用方法?

Try binding to the DataGridView.SelectedIndexChanging event ( list of all events ). 尝试绑定到DataGridView.SelectedIndexChanging事件所有事件的列表 )。 MSDN states: MSDN指出:

Occurs when a row's Select button is clicked, but before the GridView control handles the select operation. 在单击行的“选择”按钮时,但在GridView控件处理选择操作之前发生。

Another helpfull event could be probably the DataBinding event. 另一个有用的事件可能是DataBinding事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM