ASP.NET FormView 中充满控件的表,获取控件吗?

发布于 2024-08-19 23:52:45 字数 645 浏览 10 评论 0原文

获取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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

从﹋此江山别 2024-08-26 23:52:45

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.

兮子 2024-08-26 23:52:45

看来这是由于各种模板、插入、编辑、项目上的相同命名 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.

卸妝后依然美 2024-08-26 23:52:45

你有没有弄清楚这一点?如果您知道 ID,则可以使用此递归函数:

private Control FindControlRecursive(Control root, string id) 
{ 
    if (root.ID == id)
    { 
        return root; 
    } 

    foreach (Control c in root.Controls) 
    { 
        Control t = FindControlRecursive(c, id); 
        if (t != null) 
        { 
            return t; 
        } 
    } 

    return null; 
} 

在此处找到:
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:

private Control FindControlRecursive(Control root, string id) 
{ 
    if (root.ID == id)
    { 
        return root; 
    } 

    foreach (Control c in root.Controls) 
    { 
        Control t = FindControlRecursive(c, id); 
        if (t != null) 
        { 
            return t; 
        } 
    } 

    return null; 
} 

Found here:
http://www.codinghorror.com/blog/2005/06/recursive-pagefindcontrol.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文