How to get a reference to a control from its'

2019-08-15 20:00发布

How to get a reference to a control from its' string name in C#?

2条回答
老娘就宠你
2楼-- · 2019-08-15 20:08
        private Control FindControlRecursive(Control root, string id)
        {
            return root.ID == id
                       ? root
                       : (root.Controls.Cast<Control>()
                             .Select(c => FindControlRecursive(c, id)))
                             .FirstOrDefault(t => t != null);
        }
查看更多
叼着烟拽天下
3楼-- · 2019-08-15 20:19

Page.FindControl

If the Control is nested, use Control.FindControl from the parent Control. Otherwise, you'll have to write your own FindControlRecursive

查看更多
登录 后发表回答