Thursday, April 27, 2006

C# Dynamic Instantiation with Reflection

{

In our case it was a control that needed to be placed in a GridView column, but this could be used anywhere:

System.Type t = AnyControl.GetType(); // the control or class of your choice
object o = System.Activator.CreateInstance(t);
System.Web.UI.Control newControlOfType = o as System.Web.UI.Control;

}

No comments: