遞歸輸出ASP.NET頁面所有控件的類型和ID的代碼
更新時(shí)間:2012年01月12日 01:14:53 作者:
遞歸輸出ASP.NET頁面所有控件的類型和ID的代碼,需要的朋友可以參考下。
寫一個(gè)方法:
private void DisplayAllControl(Control control, int step)
{
foreach (Control ctl in control.Controls)
{
string s = new string('-', step * 4) + ctl.GetType().Name + "〈" + ctl.ID + "〉";
Response.Write(s + "<br/>");
if (ctl.HasControls())
DisplayAllControl(ctl, step + 1);
}
}
調(diào)用:
DisplayAllControl(this.Page, 0);
執(zhí)行該方法后,會在頁面中分層輸出所有控件的類型和ID值,即使是GridView、母版頁、用戶控件里的控件也不例外。
復(fù)制代碼 代碼如下:
private void DisplayAllControl(Control control, int step)
{
foreach (Control ctl in control.Controls)
{
string s = new string('-', step * 4) + ctl.GetType().Name + "〈" + ctl.ID + "〉";
Response.Write(s + "<br/>");
if (ctl.HasControls())
DisplayAllControl(ctl, step + 1);
}
}
調(diào)用:
DisplayAllControl(this.Page, 0);
執(zhí)行該方法后,會在頁面中分層輸出所有控件的類型和ID值,即使是GridView、母版頁、用戶控件里的控件也不例外。
您可能感興趣的文章:
- Jquery.TreeView結(jié)合ASP.Net和數(shù)據(jù)庫生成菜單導(dǎo)航條
- ASP.NET生成樹形顯示的GridView實(shí)現(xiàn)思路
- 常用的在數(shù)據(jù)庫中建立無限級樹形菜單的asp.net代碼
- asp.net 獲取指定文件夾下所有子目錄及文件(樹形)
- asp.net實(shí)現(xiàn)遞歸方法取出菜單并顯示在DropDownList中(分欄形式)
- ASP.NET遞歸法求階乘解決思路
- asp.net實(shí)現(xiàn)DropDownList,TreeView,ListBox的無限極分類目錄樹
- asp.net TreeView與XML三步生成列表樹
- Asp.net treeview實(shí)現(xiàn)無限級樹實(shí)現(xiàn)代碼
- asp.net TreeView遞歸循環(huán)子節(jié)點(diǎn)生成樹形菜單實(shí)例
相關(guān)文章
ASP.NET 2.0中預(yù)設(shè)的cookie
ASP.NET 2.0中預(yù)設(shè)的cookie...2006-09-09如何將數(shù)據(jù)綁到gridview然后導(dǎo)成excel
這篇文章主要介紹了如何將數(shù)據(jù)綁到gridview然后導(dǎo)成excel,需要的朋友可以參考下2014-02-02ASP.NET?Core?6框架揭秘實(shí)例演示之如何承載你的后臺服務(wù)
這篇文章主要介紹了ASP.NET?Core?6框架揭秘實(shí)例演示之如何承載你的后臺服務(wù),主要包括利用承載服務(wù)收集性能指標(biāo)、依賴注入的應(yīng)用、配置選項(xiàng)的應(yīng)用等知識點(diǎn),本文給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-03-03