如何在表单视图中找到链接按钮以便编写更改模式的代码?
我有一个包含 formview(fv) 的网络表单。 如何在其中找到链接按钮(lnkbtnEdit)以便编写更改模式的代码?
谢谢
I have a web form which contains a formview(fv).
how can I find a linkbutton within it (lnkbtnEdit) in order to write code for changing mode?
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
塞里布斯,
感谢您的回复....
但似乎我无法选择 fv 中的 lnkbtnEdit。 如果可以的话,只需在设计视图中选择它,然后在属性窗口的事件部分中,我可以编写一个处理程序来单击它......
Cerebus,
Thanks for your reply....
but it seems that I can not select the lnkbtnEdit within the fv. If I could, then simply selected it in design view, and in event section of property window, I could write a handler for clicking it....
你的问题很模糊,所以我会尽力让我的答案尽可能笼统。
ASP.NET 中的容器控件提供 FindControl< /a> 方法,使用反射在其子控件中定位具有指定名称的控件。 使用此方法是在页面或面板或模板化控件(如 FormView)中定位控件的可接受方法。
如果您想避免反射,如果您知道控件在层次结构中的索引,也可以手动定位该控件。
此外,了解需要访问此控件的时间点也非常有帮助,因为子控件很可能尚未创建。(请参阅我对您的问题的评论。)
Your question is quite vague so I'll try to make my answer as general as possible.
Container controls in ASP.NET provide a FindControl method which uses Reflection to locate the control with the specified name in their child controls. Using this method is the accepted method to locate controls within a Page or Panel or Templated control like the FormView.
If you want to avoid Reflection, you can also locate the control manually if you know the index of the control in the heirarchy.
Also, it is very helpful to know the point of time at which you need to access this control, because it is quite possible that the child control has not been created yet.(See my comment to your question.)