繁体   English   中英

页面上是否有任何列表框控件?

[英]Is there any listbox control on the page?

我想在asp.net中了解到,如何才能以编程方式了解页面上是否存在任何列表框控件?

您可以尝试...

if (Page.Controls.OfType<ListBox>().Count() > 0)
   {
       Response.Write("Listbox control exist");
   }

您需要递归检入页面的控件集合

int count =0;
private void FindControl(Control Page)

 {


 foreach (Control ctrl in Page.Controls)

 {

      if (ctrl is ListBox)

      {

         count++;
      }

      else 

      {

          if (ctrl.Controls.Count > 0)

          {

               FindControl(ctrl);

          }

      }

 }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM