using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DisplyControlTree(Page.Controls,0);
Response.Write("<hr/>");
}
private void DisplyControlTree(ControlCollection controls,int depth)
{
foreach(Control c in Controls)
{
Response.Write(new string('-',depth*4)+">");
Response.Write("控件类型:"+c.GetType().ToString ()+"控件ID"+c.ID+"<br>");
}
}
}
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DisplyControlTree(Page.Controls,0);
Response.Write("<hr/>");
}
private void DisplyControlTree(ControlCollection controls,int depth)
{
foreach(Control c in Controls)
{
Response.Write(new string('-',depth*4)+">");
Response.Write("控件类型:"+c.GetType().ToString ()+"控件ID"+c.ID+"<br>");
}
}
}
{
//窗体加载时候调用下面声明的DisplyControlTree方法
protected void Page_Load(object sender, EventArgs e)
{
DisplyControlTree(Page.Controls,0);
Response.Write(" <hr/>");
}
//创建一个方法,用foreach遍历所有控件的Type,ID,
private void DisplyControlTree(ControlCollection controls,int depth)
{
foreach(Control c in Controls)
{
Response.Write(new string('-',depth*4)+">");
Response.Write("控件类型:"+c.GetType().ToString ()+"控件ID"+c.ID+" <br>");
}
}
} 我现在不知道你问的这个帖子具体是哪不明白,如果是foreach方法你不明白,,,,,那你得好好看看基础的知识了