Devexpress在页面上查找所有控件

时间:2016-12-22 14:52:32

标签: c# asp.net webforms devexpress

如何在ASP.NET页面上找到所有DevExpress ASPxWebControls?

我试过这段代码:

foreach (var item in Page.Controls)
{
    if (item is ASPxWebControl)
    {
        (item as ASPxWebControl).Theme="Metropolis";
    }
}    

但它不起作用。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案



private void changeTheme()//this metod working in MasterPage.
        {
            for (int i = 0; i < Page.Controls[0].Controls.Count; i++)//returns masterpage
            {
                if (Page.Controls[0].Controls[i].GetType().ToString() == "System.Web.UI.HtmlControls.HtmlForm")//find htmlform in masterpage
                {
                    foreach (var item in Page.Controls[0].Controls[i].Controls)//find all controls in htmlform
                    {
                        if (item is ASPxWebControl)//reach all devexpress controls
                            (item as ASPxWebControl).Theme = "Metropolis";//change their theme
                    }
                    break;
                }
            }
            for (int i = 0; i < this.ContentPlaceHolder1.Controls.Count; i++)//find derived page's controls from masterpage
            {
                if (this.ContentPlaceHolder1.Controls[i] is ASPxWebControl)//and reach them
                    (this.ContentPlaceHolder1.Controls[i] as ASPxWebControl).Theme = "Metropolis";
            }
        }
&#13;
&#13;
&#13;

此代码在主页中查找所有devexpress控件并更改其主题。