Creating Templates Programmatically in the DataGrid Controlhttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskcreatingtemplatesprogrammaticallyindatagridcontrol.aspCreating Web Server Control Templates Dynamicallyhttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskcreatingwebservercontroltemplatesdynamically.asp

解决方案 »

  1.   

    internal class CheckBoxItem : ITemplate
    {

    void ITemplate.InstantiateIn(Control container)
    {
    CheckBox box = new CheckBox();
     

      
    container.Controls.Add(box);
    }
    }在LAOD事件里做,
    if(!ispostback)
    {
         TemplateColumn sun = new TemplateColumn();
         CheckBoxItem box = new CheckBoxItem();
    sun.EditItemTemplate = box;
    DataGrid1.Columns.Add(sun);
    }
      

  2.   

    to  houjianxun(三千弱水):
    sun.EditItemTemplate = box;
    出错,说
    d:\inetpub\wwwroot\MyLibrary\user\Resource\source.aspx.cs(242): 无法将类型“System.Web.UI.WebControls.CheckBox”隐式转换为“System.Web.UI.ITemplate”
    好象是类型不对
    internal class CheckBoxItem : ITemplate
    {

    void ITemplate.InstantiateIn(Control container)
    {
    CheckBox box = new CheckBox();
     

      
    container.Controls.Add(box);
    }
    }
    在哪写啊,有用吗
      

  3.   

    http://www.metabuilders.com/Tools/BoundBooleanColumn.aspx
    这里有你要的控件是开源的!
      

  4.   

    有关自定义的DataGridColumn的资源!
    http://www.microsoft.com/china/msdn/library/dnaspp/html/creatingcustomcolumns.asp