循环遍历一个控件方法

        public static StringBuilder RecursiveControl(Control ct)
        {
            StringBuilder sb 
= new StringBuilder();
            RecursiveControl(ct, 
0 ,sb);
            
return sb;
        }

        
public static void RecursiveControl(Control ct,int xc,StringBuilder sb)
        {
            xc
++;
            
            
if (ct != null)
            {
                
for (int i = 0; i < ct.Controls.Count; i++)
                {
                    
for (int j = 1; j < xc; j++)
                    {
                        sb.Append(
"-");
                    }
                    sb.Append(ct.Controls[i].ToString());
                    sb.Append(
"<br/>");
                    RecursiveControl(ct.Controls[i],xc,sb);
                }
            }
            
        }
调用方法:
        StringBuilder sb = SharedClass.RecursiveControl(DataList1);
        Response.Write(sb.ToString());

posted on 2006-04-05 20:55  Sunny  阅读(256)  评论(0编辑  收藏  举报