熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET中遍歷頁面的所有button控件

2022-06-13   來源: .NET編程 
通用代碼
    public static ArrayList BtnList(SystemWebUIControl page)
    {
        int nPageControls = pageControlsCount;
       
        ArrayList btnText = new ArrayList();
        for (int i = ; i < nPageControls; i++)
        {
            foreach (SystemWebUIControl control in pageControls[i]Controls)
            {
                if (control is Button)
                {
                    //btnTextAdd(controlID);
                    btnTextAdd((control as Button)Text);
                }
            }
        }
       
        return btnText;
    }
   頁面調用代碼
 
    protected void Page_Load(object sender EventArgs e)
    {
        ArrayList arrayList = new ArrayList();
        SystemWebUIPage page = (SystemWebUIPage)HttpContextCurrentHandler;
        arrayList = BtnCtrListBtnList(page);
 
        foreach (object o in arrayList)
        {
            ListBoxItemsAdd(oToString());
        }
    }
From:http://tw.wingwit.com/Article/program/net/201311/15466.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.