不過以下方法在複製一些有很多層屬性的控制項時好像不能完全複製=.="

在Page_Init裡呼叫

public Control CopyControl(Control ctrlSource,string Control_ID)  
         {  
             Type t = ctrlSource.GetType();  
       
             Control ctrlDest = (Control)t.InvokeMember("", System.Reflection.BindingFlags.CreateInstance, null, null, null);

             foreach (System.Reflection.PropertyInfo prop in t.GetProperties())
             {
                 if (prop.CanWrite)  
                 {  
                     if (prop.Name == "ID")  
                     {
                         ctrlDest.ID = Control_ID;                      
                     }  
                     else  
                     {  
                         prop.SetValue(ctrlDest, prop.GetValue(ctrlSource, null), null);  
                     }  
                 }  
             }  
       
             return ctrlDest;  
         } 

welkingunther 發表在 痞客邦 PIXNET 留言(0) 人氣()