简体   繁体   English

DataGrid的OnItemCommand事件未触发

[英]OnItemCommand Event of the DataGrid is not firing

I am having a DataGrid in one usercontrol which is getting filled with some data when I press some button(ouside it). 我在一个用户控件中有一个DataGrid,当我按下某个按钮(将其隐藏)时,该控件已充满了一些数据。 This Datagrid is filled by one linkbutton also. 这个Datagrid也由一个linkbutton填充。 When I click this LinkButton then OnItemCommand or SelectedIndexChanged should fire, but both the events are not firng. 当我单击此LinkBut​​ton时,应触发OnItemCommand或SelectedIndexChanged,但两个事件均不会触发。 While the control's PageLoad event is firing. 当控件的PageLoad事件触发时。

Please let me know where I am doing the mistake. 请让我知道我在哪里做错了。

Thanks 谢谢

Is your control added dynamically, using something like Page.LoadControl()? 是否使用Page.LoadControl()之类的控件动态添加了控件? If so, events won't fire unless the control is dynamically added for each request. 如果是这样,除非为每个请求动态添加控件,否则事件不会触发。 That's the only way the control tree can be properly built again. 这是可以再次正确构建控制树的唯一方法。 I usually do this in Init(). 我通常在Init()中执行此操作。

http://www.4guysfromrolla.com/articles/042402-1.aspx http://www.4guysfromrolla.com/articles/042402-1.aspx

For those that see this post, looking for an answer. 对于那些看到这篇文章,寻找答案的人。 Most likely, you're rebinding the data to the datagrid on every call. 最有可能的是,您将在每次调用时将数据重新绑定到数据网格。 Use a conditional and check !this.IsPostBack. 使用一个有条件的并检查!this.IsPostBack。

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

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