递归遍历页面控件

        private Control returnCtrl;
        
/// <summary>
        
/// 递归遍历页面控件
        
/// </summary>
        
/// <param name="oControl"></param>
        private Control LoopingControls(Control oControl)
        {
            
foreach (Control frmCtrl in oControl.Controls)
            {
                
if (frmCtrl is GridView)
                    
if (((GridView)frmCtrl).ID == ControlToPaginate)
                    {
                        returnCtrl 
= frmCtrl; break;
                    }

                
if (frmCtrl is Repeater)
                    
if (((Repeater)frmCtrl).ID == ControlToPaginate)
                    {
                        returnCtrl 
= frmCtrl; break;
                    }

                
if (frmCtrl is BaseDataList)
                    
if (((BaseDataList)frmCtrl).ID == ControlToPaginate)
                    {
                        returnCtrl 
= frmCtrl; break;
                    }

                
if (frmCtrl.HasControls())
                    LoopingControls(frmCtrl);
//递归遍历
            }
            
return returnCtrl;
        }
        
#endregion
posted @ 2007-10-27 11:34  无锋不起浪  阅读(1184)  评论(4编辑  收藏  举报