我调试过:
_Body.Columns.Add(col);后ReportActionColTemplate2 的InstantiateIn过程会执行一次
 container.Controls.Add(GetBody())后ReportActionColTemplate2 的InstantiateIn过程也会执行一次,不知道InstantiateIn的执行原理是什么?

解决方案 »

  1.   

    我也试过:
    如果不是DataGrid不嵌套在DataList中,而是单独一个类,就不会出现这个问题
      

  2.   

    if you look at the code inhttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondevelopingtemplateddataboundcontrol.aspafter the template is instantiated, it calls DataBind() on the container, because you have _Body.DataBind() in GetBody(), _Body.DataBind() method is actually called twice, try
    public DataGrid GetBody(){             
                DataGrid _Body=new DataGrid();
                TemplateColumn col= new TemplateColumn() ;                              
                col.ItemTemplate =  new ReportActionColTemplate2();                                                                      
                _Body.Columns.Add(col);              
                _Body.DataSource=new int[]{1,2,3,4,5};
                //_Body.DataBind();                             
                _Body.ID="OnePage"+itemcount.ToString();                      
                return _Body;           
            }    
    also, you understand you have another column "Item" is coming from the data itself, right?
      

  3.   

    谢谢saucer(思归/MVP),问题已经解决