使用Predicate 的递归FindControl

2015-12-01 0 168
使用Predicate 的递归FindControl
    public static T FindControl<T>(this Control control, Predicate<Control> expression) where T: Control
    {
        T tmp = null;
        if (control.HasControls())
        {            
            foreach (Control ctrl in control.Controls)
            {
                if (tmp == null)
                {
                    if (ctrl is T)
                    {
                        if (expression == null || expression.Invoke(ctrl))
                            return (ctrl as T);
                    }
                    else
                    {
                        if (ctrl.HasControls())
                            tmp = FindControl<T>(ctrl as Control, expression);
                    }
                }
                else break;
            }
        }
        return tmp;
    }

遇见资源网 ASP/Basic 使用Predicate 的递归FindControl http://www.ox520.com/13551.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务