根据指定的控件ID获取相应的控件

我用此方法主要用于找到GridView中的控件,核心代码如下:

 1 public static Control getChildControl(Control ctl, string ControlID)
 2    {
 3        foreach (Control cctl in ctl.Controls)
 4        {
 5            if (cctl.ID == ControlID)
 6            {
 7                return cctl;
 8            }

 9            else
10            {
11                Control ctl2 = getChildControl(cctl, ControlID);
12                if (ctl2 != null)
13                {
14                    return ctl2;
15                }

16            }

17        }

18        return null;
19    }
posted @ 2007-09-26 09:36  sunfishlu  阅读(1052)  评论(0编辑  收藏  举报