思归等高手请进:如何hook在datagrid中动态添加的控件
datagrid中动态添加控件是容易的,只需要在ItemDataBound事件的处理函数中
e.Item.Cells(1).Controls.Add(myServerControl)
就可以了,
hook在form中动态添加的空间是容易的,见
http://support.microsoft.com/kb/317515/EN-US/
HOW TO: Dynamically Create Controls in ASP.NET with Visual Basic .NET
现在,想在datagrid中动态添加控件,并hook它,上文中提到:
Note
When you create dynamic controls on a Web Form, you must create the controls and add them to the controls collection in either the Page_Init event handler or the Page_Load event handler. Otherwise, the controls may not behave as expected.
这就矛盾了,我试着只是把controls.add的地方从page_init改到myDataGrid_ItemDataBound中,就hook不到了。
有什么办法吗?多谢!