开发者

Is there any listbox control on the page?

开发者 https://www.devze.com 2023-03-31 02:19 出处:网络
I want to learn that in asp.ne开发者_如何学Got, how can we understand is there any listbox control on the page programmatically?You can try like...

I want to learn that in asp.ne开发者_如何学Got, how can we understand is there any listbox control on the page programmatically?


You can try like...

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


You need to check in a Page's control collection recursively

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);

          }

      }

 }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消