开发者

Table filled with controls inside an ASP.NET FormView , get controls?

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.kataSistimataForm开发者_如何学CView.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;


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜