TextBox tt=new TextBox();
        
        foreach (Control mc in Page.Controls)
        {
            foreach (Control cc in mc.Controls)
            {
                if (cc.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
                {
                    tt = (TextBox)cc;
                    tt.Text = "1";
                    tt.ReadOnly = true;
                }
            }

           
        }

以后为嵌套实现:
 private void test(Control c)
    {
        foreach (Control childControl in c.Controls)
        {
            if (childControl is TextBox)
                ((TextBox)childControl).Text = "2";
            else
                test(childControl);
        }
    }
调用时用: 
test(this.Page)
 posted on 2007-01-18 15:09  心有灵犀  阅读(378)  评论(0)    收藏  举报