ASP.NET FormView 中充满控件的表,获取控件吗?
获取FormView内部控件的技巧是什么?我用 FindControl() 获取它们,但是现在我无法访问它们。示例:我在 FooterTemplate 上有一些 ImageButton,太好了,当涉及到 FormView 内的控件时,我可以顺利地获得这些按钮!将每个控件置空。您认为我应该在每个模板中以不同的方式命名它们吗? 这让我想起了桌子造成的噪音!
我正在使用 DataBound 事件并检查特定模式!有什么想法吗?谢谢。
[更新]
这是有效的
if (this.kataSistimataFormView.CurrentMode == FormViewMode.Edit)
{
ImageButton update = (ImageButton)this.kataSistimataFormView.FindControl("btnUpdate");
update.Visible = true;
,但是由于某种原因没有
CheckBox chkBoxPaidoi = kataSistimataFormView.FindControl("chkBoxPaidoi") as CheckBox;
What is the trick to get the controls inside the FormView. I was getting them with FindControl() but, now i cant get access on them. Example: i have some ImageButton on the FooterTemplate, great i can get those smoothly, when it comes to the controls inside the FormView!!! null every control. Do you think i should name them differently in every template?
This gets me thinking about the table causing this noise!
I'm using the DataBound Event and checking for specific Mode! Any ideas? Thank you.
[UPDATED]
This is working
if (this.kataSistimataFormView.CurrentMode == FormViewMode.Edit)
{
ImageButton update = (ImageButton)this.kataSistimataFormView.FindControl("btnUpdate");
update.Visible = true;
But this for some reason no
CheckBox chkBoxPaidoi = kataSistimataFormView.FindControl("chkBoxPaidoi") as CheckBox;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
FindControl 不是递归的。我的意思是,它只会查找您正在搜索的控件的子控件内的控件 - 它不会搜索子控件的任何子控件
如果您已将之前要查找的控件放置在另一个控件中,那么您必须在该新控件内进行搜索,或者,如果您仍想使用 kataSistimataFormView 作为父控件,则可能必须使用递归搜索。
谷歌搜索“findcontrol recursive”有一些很好的例子,你可以直接剪切和粘贴。
FindControl is not recursive. What I mean is that it will only find controls that are within the child controls of the control you are searching - it will not search any child controls of the child controls
If you have placed the control you previously were looking for within another control then you will have to either search within that new control or, if you still want to use kataSistimataFormView as the parent control, you may have to use a recursive search.
Google for "findcontrol recursive" there are some good examples that you can probably just cut-and-paste.
看来这是由于各种模板、插入、编辑、项目上的相同命名 ID 造成的。即使编译器支持这一点,当您稍后以编程方式获取它们时也会出现问题。
谢谢大家。
As it seems this was caused because of the same naming ID's on various templates, Insert,Edit,Item. Even this is supported by the compiler, has problem when you are going for them programmaticaly later.
Thank you all.
你有没有弄清楚这一点?如果您知道 ID,则可以使用此递归函数:
在此处找到:
http://www.codinghorror.com/blog/2005/06/recursive -pagefindcontrol.html
Did you ever get this figured out? If you know the ID you can use this recursive function:
Found here:
http://www.codinghorror.com/blog/2005/06/recursive-pagefindcontrol.html