日期:2014-05-20  浏览次数:20919 次

请问foreach中如何传递控件的类型???在线等!!!
我现在把foreach写在一个自定义函数里面,函数体如下所述

                public   static   void   ForeachCtrl()
                {
                        foreach   (Control   ctrl   in   this.Controls)
                        {
                                if   (ctrl   is   TextBox)
                                {
                                        .....
                                }
                        }
                }

我想在调用这个函数的时候,TextBox这里可以用其他类型来替换,这样子的话,我在主程序地方只要定义我想要遍历的控件类型,这里就能查找出来。。。

不知道这样子说,各位高手能否明白,谢谢!!!

------解决方案--------------------
public static void ForeachCtrl(System.Type t)
{
foreach (Control ctrl in this.Controls)
{
if (typeof(ctrl).FullName==t.FullName)
{
.....
}
}
}
这样应该可以吧
传进控件的typeof(ctrl)
------解决方案--------------------
public static void ForeachCtrl( Type t)
{
foreach (Control ctrl in this.Controls)
{
if (ctrl.GetType() == t )
{
.....
}
}
}

------解决方案--------------------
呵呵 解决了吧
------解决方案--------------------
楼上可以
------解决方案--------------------
学习
------解决方案--------------------

or
public static void ForeachCtrl( System.Web.UI.Control control )
{
foreach (Control ctrl in this.Controls)
{
if (ctrl.GetType() == control.GetType() )
{
.....
}
}
}