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
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
{
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);
}
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);
}
}
在哪写啊,有用吗
这里有你要的控件是开源的!
http://www.microsoft.com/china/msdn/library/dnaspp/html/creatingcustomcolumns.asp