循环遍历一个控件方法
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 = 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());
Response.Write(sb.ToString());