将 LinkButtons 添加到 ItemDataBound 中的 DataGrid 行
我有一个相当标准的 DataGrid。它包含一些 BoundColumn。 我正在重载其中一列以包含文本或 LinkButton,具体取决于绑定项目的某些特征。
所以..在网格的 ItemDataBound 事件中,我检查了一些内容并将标签控件或 LinkButton 控件添加到正确的单元格。
如果我单击这些 LinkButton 之一,则会发生回发,但它不会调用按钮的事件处理程序中的方法。
我看到有些人说如果您在 PreInit 页面事件之后创建控件,事件将不起作用。这是真的吗?如果是这样,我必须有一种方法可以手动连接它们?
我尝试在 PreInit 中创建所有按钮,然后仅将它们添加到 ItemDataBound 中,这毫不奇怪地不起作用。
我听其他人说按钮和每个父控件必须有一个唯一的 ID。这是真的吗?
我不想盲目地放弃这一点,而是想确切地了解为什么我不能这样做。
谢谢
I have a fairly standard DataGrid. It contains a few BoundColumns.
I'm overloading one of these columns to contain either text or a LinkButton depending on some characteristics of the bound item.
So.. in the ItemDataBound event for the Grid, I check a few things and add either a Label Control, or LinkButton Control to the proper Cell.
If I click on one of these LinkButtons, a postback occurs, but it does not call the method in the event handler of the button.
I have seen some people say that events will not work if you create controls AFTER the PreInit page event. Is that true? If so, there must be a way I can manually wire these up?
I have tried creating all of the buttons in PreInit and only adding them in ItemDataBound which unsurprisingly did not work.
I have heard others say the buttons and each parent control must have a unique ID. Is that true?
Rather than blindly swing away at this, I'd like to understand exactly why I can't do this.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我了解,如果您将链接按钮放入 DataGrid 中,则需要使用 RowCommand,即
然后您需要将 OnRowCommand 事件绑定到 DataGrid 中的函数。这将传递给链接按钮的命令参数以及事件参数中的命令名称。您可以使用它来对事件做出适当的反应。
As far as I understand it, if you put a link button inside a DataGrid you need to use the RowCommand, i.e.
Then you need to bind the OnRowCommand event to a function in your DataGrid. This will pass the Command Argument that was given to link button and the name of the command in an Event Argument. You can use this to re-act appropriately to the event.